Corny titles aside, this post is to get across to Chantelle of Waiver Sharks how to include WPAds Banners in The Loop (a WordPress term, I’ll explain in a sec). If you haven’t read it yet, here is the post about the uses of WPAds in your posts. In that post I described how to use (or re-use) HTML code or text in posts but not all posts, just a chosen few. It’s handy if you want to add HTML widgets into a post for example, or to include advertising specific to a series of posts, like I’m doing throughout the Blog Series. The advertisement that shows up on the right side in the Blog Series posts rotates between different ads and I use WPAds to do it. That ad will be included in each new post in the series. If I decided to remove an ad from the rotation (or add one), I do so within the WPAds admin and all instances of it will be affected. Very cool stuff…. but that apparently wasn’t enough for WaiverSharks :) They want to be able to add a WPAd banner in all posts new and old automatically.
Including WPAds In The Loop
I often show ads at the bottom of each and every post throughout this blog. To accomplish that I needed to include code in The Loop. Here’s a partial definition of The Loop from WordPress.org:
The Loop is used by WordPress to display each of your posts. Any HTML or PHP code placed between where The Loop starts and where The Loop ends will be used for each post.
From my understanding of The Loop, there are 4 main instances of it. You can find them in the Theme Editor in various theme files. You see, your posts exist on multiple pages of your site. They are shown on the main page, the archives (categories, calendar), they have their own page and they are also on the search results.
Different files with different code have been created to show your posts. It entirely depends on your theme how your posts are displayed on various pages. You can include your code (or WPAd banners) on some or all of these pages. If you want ads at the bottom of each post, for every single instance of the post, for example, you would need to put the banner on all 4 of the themes pages that show the posts. Each theme is different but from the Theme Editor you should see something similar to: Archives, Main Index Template, Search Results and Single Post. Each of these files has code that loops through displaying the posts one at a time (The Loop). Single Post still has it but loops through only once.
The WPAd Code To Use
For each zone your are given code for posts and code for templates. We will need the code for templates here, it will be the code wrapped in php tags.
Your Loop code will look different based on the file you are looking at and the theme you are working with. I realize that all of these differences make this sound pretty difficult but it’s not too bad. Don’t be frightened by all of the code. Just make sure you backup the file you are working with in case it doesn’t do what you want it to do. It might take a couple of tries, but you can do it. :)
Here is what it might look like:
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
// a bunch of loop code
<?php wpads('Zone_Name'); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
Save the file (you backed it up first right?), quickly load your site and see if it worked.
Thanks for the question Waiver Sharks. Good luck!





















March 22, 2008 at 5:02 am
very useful info, how do you find these ads performing? I’ve seen them on the bottom of posts on quite a few blogs now..
Andy Bailey’s last blog post..Awesomely awesome way to give away free gadgets and money…
March 22, 2008 at 9:19 am
Thanks for the mention Keith! I will definitely be making use of this in the near future! As always, a great read, and very useful information.
WaiverSharks’s last blog post..WELCOME
March 22, 2008 at 11:43 am
@Andy…so far so good, they have been throwing some errors the last couple of days though