View Single Post
  #1   IP: 218.85.132.244
Old 2008-02-19, 02:33 AM
car car is offline
高级会员
 
Join Date: 2006-05-14
Posts: 534
car 正向着好的方向发展
Default How To Put Ads on WordPress Home Page Only

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:

Code:
<?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”.
Reply With Quote