Recent Topics

1 Dec 14, 2006 17:02    

Here is a groovy little skin-level hack that will let you put *something* after the first post is displayed, then *something else* after the second post is displayed. The *something* bit will show up after every 'first post', meaning no matter how many times a visitor clicks through to more full pages in your archives it'll be there. It'll also be on every permalink page after the comments section. It won't show up on pages like profile and archives though, because there is no post displayed.

*something* could be your google adsense stuff eh? *something else* could be whatever you see fit to display on a multipost page in the main post area, but only want to display once. Heck it could be the same as *something* if that's what makes you happy.

You can add SOMETHING after the FIRST post, SOMETHING after the SECOND post, or SOMETHING after the FIRST post and SOMETHING ELSE after the SECOND post. This third option is what you see in action at http://ahga.org. The first option is known to work because that's what I did before I built in the *something else* bit. Therefore if you like the second option you might find it doesn't work. If so it'll probably be easy to fix so check it out and we'll fix whatever needs fixing.

No matter which option of the three you want to use, open your skins/your_skin/_main.php and find something that looks like this:

			// ---------------- END OF INCLUDE FOR COMMENTS, TRACKBACK, PINGBACK, ETC. ----------------

			locale_restore_previous();	// Restore previous locale (Blog locale)
		?>
	</div>
	<?php
	} // ---------------------------------- END OF POSTS ------------------------------------
	?>

To add SOMETHING after the FIRST post change it to this:

			// ---------------- END OF INCLUDE FOR COMMENTS, TRACKBACK, PINGBACK, ETC. ----------------

			locale_restore_previous();	// Restore previous locale (Blog locale)
		?>
	</div>

<?php // --------- SOMETHING OR SOMETHING ELSE INCLUDED ONCE EACH HERE ---------
if( ! $first_post_done ) {
	require( dirname(__FILE__).'/_something.php' );
	$first_post_done = true;
	}
// ------------------- END OF SOMETHING OR SOMETHING ELSE ------------------- ?>

	<?php
	} // ---------------------------------- END OF POSTS ------------------------------------
	?>

To add SOMETHING after the SECOND post change it to this:

			// ---------------- END OF INCLUDE FOR COMMENTS, TRACKBACK, PINGBACK, ETC. ----------------

			locale_restore_previous();	// Restore previous locale (Blog locale)
		?>
	</div>

<?php // --------- SOMETHING OR SOMETHING ELSE INCLUDED ONCE EACH HERE ---------
if( ! $first_post_done ) {
	$first_post_done = true;
	} elseif ( ! $second_post_done ) {
	require( dirname(__FILE__).'/_something.php' );
	$second_post_done = true;
	}
// ------------------- END OF SOMETHING OR SOMETHING ELSE ------------------- ?>

	<?php
	} // ---------------------------------- END OF POSTS ------------------------------------
	?>

To add SOMETHING after the FIRST post and SOMETHING ELSE after the SECOND post change it to this:

			// ---------------- END OF INCLUDE FOR COMMENTS, TRACKBACK, PINGBACK, ETC. ----------------

			locale_restore_previous();	// Restore previous locale (Blog locale)
		?>
	</div>

<?php // --------- SOMETHING OR SOMETHING ELSE INCLUDED ONCE EACH HERE ---------
if( ! $first_post_done ) {
	require( dirname(__FILE__).'/_something.php' );
	$first_post_done = true;
	} elseif ( ! $second_post_done ) {
	require( dirname(__FILE__).'/_something_else.php' );
	$second_post_done = true;
	}
// ------------------- END OF SOMETHING OR SOMETHING ELSE ------------------- ?>

	<?php
	} // ---------------------------------- END OF POSTS ------------------------------------
	?>

Now be creative and make files called _something.php (and _something_else.php if you are adding two custom bits) in your skins/your_skin/ folder. Each of them needs to look something like this:

<?php 
/*
 * This is a custom page that adds *something* or *something else* after the first or second post displayed on a page.
 *
 * Do NOT remove the "if ! defined ... " line unless you want hackers to eat your babies!!!
 */

if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

echo 'This is where you put your custom code.  It can be anything you want.<br />';
echo 'It will be inside your "posts" loop (<div class="bPosts">), but NOT inside a post (<div class="bPost">).<br />';

?>

<div class="bPost">
<p>You can use regular html code if you want, just remember to use appropriate divs and classes.</p>
</div>

<?php 

echo 'You can also mix and match php and html.  I have not tested it, but I think it will also know about the post it just displayed via $Item.<br />';
echo 'That is hard to take advantage of though because the first post displayed will always be different depending on if your visitor is <ul>';
?>

<li>at an entry page</li>
<li>looking at a specific category</li>
<li>has clicked 'previous' a few times</li>

<?php 
echo '<li>is on a permalink page</li>';
echo '</ul>'."\n";

?>

By the way, this will work in any version of b2evolution ever released.

EDIT: The something bit shows up after (not before) comments on a permalink page.

2 Dec 15, 2006 02:26

I tried this hack out.

First, I had to remove the "echo" lines, as they showed up on my blog.

Second, it did post something after the first post, but none of the other posts showed up, and the right column (I have a three column blog) appeared immediately after the "something," so, in essence, I now had a two column blog.

3 Dec 15, 2006 06:19

I hadn't thought of three column blogs, but I can't imagine why it would break the layout. What did your _something.php page end up looking like? The echo lines were in the sample only to be a sample. Same with the html stuff. You would, of course, replace all of it with whatever you wanted to display between posts. Do you have a place I can see it failing?

4 Dec 15, 2006 11:50

Here's the code:

<?php
/*
 * This is a custom page that adds *something* or *something else* after the first or second post displayed on a page.
 *
 * Do NOT remove the "if ! defined ... " line unless you want hackers to eat your babies!!!
 */

if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

?>

<div class="bPost">
<p><script src="http://feeds.feedburner.com/comiclistfeed?format=sigpro" type="text/javascript" ></script><noscript></p>
</div>

I removed the hack when it did not work as planned. But I'll try to get it up somewhere for you to see.

5 Dec 15, 2006 12:02

I wonder if having a <noscript> tag without having a </noscript> tag is an issue? I can't imagine how it could break your blog, but it's the only thing I see in your file that might be an issue.

More support tomorrow as it's way past my bedtime.

6 Dec 16, 2006 02:23

EdB wrote:

I wonder if having a <noscript> tag without having a </noscript> tag is an issue? I can't imagine how it could break your blog, but it's the only thing I see in your file that might be an issue.

Good call! I removed it and it works. It does produce the following "error log" entries, though:

[Fri Dec 15 19:29:38 2006] [error] PHP Notice: Undefined variable: first_post_done in /home/comlist/public_html/skins/Stockholm_remix/_main.php on line 571
[Fri Dec 15 19:29:29 2006] [error] PHP Notice: Undefined variable: second_post_done in /home/comlist/public_html/skins/Stockholm_remix/_main.php on line 574

7 Dec 16, 2006 02:49

I wondered if it was okay to "just assume" an undefined variable would not equal true. Perhaps it works but it's not the best way to do business eh? Let's try something and see if you continue to see that error entry. Again in your _main.php file way up at the top add another line:

if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); // this line already exists
$first_post_done = $second_post_done = false;

This way we're officially stating that those variables exist and that they are false. I'm guessing this will stop those lines from showing up in your error log file. I just checked mine at ahga.org and don't see the same thing, so I can't really test this issue & solution myself.

8 Dec 16, 2006 02:57

That appears to have taken care of the errors.

html://www.comiclist.com

If you'd like to see your hack at work.

Now if I could just clear up the ministats and sideblog errors, I'd be curiously satisfied with my blog. :)


Form is loading...