Folks, since my site has gotten fairly popular I have people who want to advertise on the home page. The problem is that I didn’t know of a good method of embedding Ads that only show up on the home page and don’t appear site wide. (And not in the sidebar.)
I needed to employ a little PHP trickery in order to get this to work and I figured I’d share the methodology in case anyone else wanted to do this, or had a better idea as to how to pull it off.
In my case what I did was edit the Index.php file and added the following code to the bottom of the page inside the loop:
EDIT: Thanks to Storm for dropping me a comment with an even simpler method which came from Douglas Karr. Here it is:
<?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>
PLACE ADVERTISEMENT HERE.
<?php } ?>
What this does is causes the ads to appear on the Homepage, but not on any of the other Category or Archive “pages”.







I was looking for just that, and found it here:
http://www.douglaskarr.com/2006/09/06/wordpress-hack-after-the-first-post-only-on-the-home-page/
Storm,
Thanks for the tip it worked perfectly! I’ve updated the article to reflect the change. I really appreciate it.
John
Thank you a lot for this hint, I will start using it after I add this comment :)
Nice one. Will definitely plug it in my blog. Thx :-)
Thanks for the code–I will certainly implement it on my blogs.
Does anybody know of similar code that can be used for any/all php scripts, not just wordpress?
Hi, I am wondering how can I go to the index.php to my theme, I realli want to put ads on my blog but can’t do it yet..help pls..
To bad I don’t use adsense on most of my blogs :))
Many many thanks for the tip. I have been looking for the answer on how to do it with Tigopedia Reloaded WP theme (it doesn’t separate page for homepage and category/archive), and your tip works very well.
Glad that helped you out Heris! :-)
Sorry Madel, it looks like you are using WordPress.com and I’m not sure how, or if, you can edit the themes there. This tip was really for the stand-alone WordPress that can be downloaded from WordPress.org.
John