On one of my other sites we run advertising, a banner ad. Because I haven’t had time until today to figure out how to get the ad to appear after the first posting on a page, we’ve been putting the ad on every page of the site, except the home page. The include code is in the footer of the page, so the ad ended up down at the bottom of the page. Not really an optimal place for visibility. So I’ve been digging through the WordPress docs and found the way to do it.
I tried adding an if statement inside the loop, using next_post_link(). But that variable is the same for the entire page. So then I looked for a “first_post” variable, but there isn’t one. So I created one.
In index.php in my template, I added this code:
<?php $ppl=$ppl+1; if ($ppl==1) include("ad-block.html"); ?>
just after the <p class=”postmetadata”> section, and before the <?php endwhile; ?> section. So now when the $ppl variable is equal to one, the ad-block.html file is included, at other times, nothing is. You could easily use this to have a different text (or included text) show up after different posts. For example, after every second post. Or a different piece of text for the 4th posting on a page.
You can see this on my DC Area Theater information blog, ShowBizRadio.net.