Placing an Ad Between 1st & 2nd Post – Wordpress
Posted by: admin in CMS, Web Development Tags=Okay i’ve got a new one for you! What if you need to place a banner ad between the 1st and 2nd blog posts only in the Wordpress “Loop“? How exactly would you go about doing that? I recently had a client ask me for this feature and I was not sure at all how to do it. Thanks to Google and some PHP goods here is how I got it done…
Here’s what your Wordpress Loop basically looks like in your index.php or archive.php files etc.
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- do stuff -->
<?php endwhile; ?>
<?php endif; ?>
The following code will help you place an ad between the 1st and 2nd blog posts in your Wordpress Loop:
<?php
$postcounter = 1; // set counter to 1 for ads
if (have_posts()) : ?>
<?php while (have_posts()) : $postcounter = $postcounter + 1;
the_post(); ?>
<!-- do stuff -->
<?php if(2 == $postcounter) {
echo
'
<div id="adsbetween">
<-- Place ad code here -->
</div>
'
; } ?>
<?php endwhile; ?>
<?php endif; ?>
Try that. That should work just fine for you! You can learn more here at this url. http://www.nzwhost.com/article/placing-adsense-between-posts











Entries (RSS)
October 20th, 2008 at 8:01 am
I just stumbled across your blog, and really appreciate your in depth posts. I feel a lot of time it’s hard to get the meat from most web development blogs. So, here’s my question for you. I have seen a growing trend for people to offer free SEO wordpress themes (see here and here). I understand how to add plugins to make the theme more SEO friendly, but I am curious what makes a theme SEO-ed right out of development. Any insights would be appreciated. ~Paul