Have you ever tried to insert advertisements (or any bit of code really) into the WordPress post loop, then found that it will insert the banner after each post? It really depends on what you are going for, but this usually will not be an ideal solution to placing advertisements between posts on your homepage. If you’d like to place something only after the first post in the WordPress post loop, here is a quick hack you can do to tell WordPress to only display it after the first post.
Simply go to your themes homepage and look for the following code:
<?php endwhile; ?>
Immediately before this code, place the following code:
<?php if(!$show_ads){ ?>
Insert Code Here
<?php $show_ads = 1; } ?>
Obviously you’ll want to replace Insert Code Here with your code. Told you it was easy!



Tuesday, August 19th, 2008 at 7:11 pm
I need to put adverts into my post, not just in widget and the sidebar. I’ve bookmarked your page to remind me of what to do. Many thanks
Ian
Wednesday, August 20th, 2008 at 8:53 am
If only everything were that simple
Wednesday, August 20th, 2008 at 8:19 pm
Thanks Kyle, this is simple and easy.
Friday, August 22nd, 2008 at 8:07 am
Glad everyone found it both easy and useful!
Wednesday, August 27th, 2008 at 8:20 pm
hey, is there any way to put the ad after say, the 3rd post? is it as simple as changing the to ???
Thanks!
Saturday, August 30th, 2008 at 2:04 pm
HackWordpress rulezz!
Saturday, August 30th, 2008 at 7:34 pm
On a blog of mine, i use Adsense in the main index template, and 3 occurences of the banner appear on the homepage, as this is the max allowed by Google per ad unit.
However on the 4th and remaining posts, there is an ugly space. I will try your hack and hope this helps it.
Missy.
Sunday, August 31st, 2008 at 7:52 am
What about simply using this code:
Your code here…
Sunday, August 31st, 2008 at 7:57 am
hmm… I should have known code will not be published…
your code here
What about this?
Sunday, August 31st, 2008 at 7:57 am
Well… that’s working great…
Sorry!
Sunday, September 14th, 2008 at 11:43 am
nice hacks..
keep it up.
Tuesday, January 6th, 2009 at 3:14 am
thanks a lot for that, its such a simple snippet of code and very simple instructions
you are a living legend!
see ya
ET
http://tariksport.com/nfl-blog/
Trackbacks/Pingbacks
Leave A Comment
Become one of our
Featured Sites
Recent Trackbacks
Contributing Authors
Archives
Extras
WordPress Hacks Copyright © 2007-2009 | An Apricot Media Website
Template by Revolution Themes | Custom Design by Kyle Eslick and Blog Design Studio
RSS Feed Email RSS