PHP :WORDPRESS : Place banner between posts
I thought it would be nice to share you a little piece of script that I use on this website, with this modification in my theme I can show banners where i want them to be, I’ve decided to do this to keep some load off the sidebox, and some banners between posts are real eye catchers! Applying these changes requires basic programming skills and should not take any longer than 10 minutes.
Step 1
First or all you have to determine what theme you are running,to do this click on the presentation tab, in the administration panel.
now you can see your current theme and the locations of the files relative to your blog.
Step 2
Connect to your website with your favorite FTP Browser and go to the folder we have found in step one, now we have to find a file that handles the posts, this can vary from theme to theme, in default theme this file is called page.php and it looks like this.
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Step 3
All we have to do know is add the modifications and define the ads/banners that have to be shown and where they have to be shown. here is the modified code.
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<?php
// change part 1
// we have to set this value to keep track what the number of the current post is.
$count_post = 1;
// end -> change part 1
if (have_posts()) : while (have_posts()) : the_post();
?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
</div>
<?php
// Change part 2
// after the first post
if ($count_post == 1) {
$buff="<div style=\"margin:5px; padding:5px;\"><center>".adsensem_ad('ad-468')."</center></div>";
echo $buff;
}
//end -> after the first post
// after the third || fifth || seventh post
if ($count_post == 3 || $count_post == 5 ||$count_post == 7) {
$buff="<div style=\"margin:5px; padding:5px;\"><center><script type=\"text/javascript\" src=\"\"></script></center></div>";
echo $buff;
}
//end ->after the third || fifth || seventh post
// set the new track number (old value +1)
$count_post++;
// end -> Change part 2
?>
<?php endwhile; endif; ?>
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
As you can see I’ve added $count_post this value will keep track of the post numbers.
before endwhile; is where all the action takes place, In this case the are 2 different ads, the first one will be shown only after the first post , the second howeven will be shown after the 3th, 5th and 7th post, ofcourse you can change these values to whatever you want.
In my case the first ad is managed with Adsense Manager The second advertisement is using an javascript banner randomizer offered by many affilate programs ,like NeverBluAds
if you plan to use this, or if there is something not clear, or need help applying this code, leave a comment and I’ll try to help you.
Tags: hack, wordpress, wordpress modification
























March 15th, 2008 at 8:41 am
Thanks for sharing that. Good way to customise the ad and banner units that appear between posts.
Andrew’s last blog post..Productivity tips revisited
March 15th, 2008 at 3:56 pm
I’ve been looking for that for my other blog. Thanks for sharing!
Crystal’s last blog post..12 Awesome Blog Category Ideas And Others
October 23rd, 2009 at 12:02 am
You might be able to decipher the nuts and bolts, but in the end, you can’t unscramble the mystery of how music makes you feel. ,
January 15th, 2010 at 2:56 pm
High and dry
January 17th, 2010 at 10:50 am
blog did exactly what you said it does. Your site is great to work with. I can’t say enough about blog.
February 13th, 2010 at 11:11 am
Download and listen Free songs - http://www.angnetwork.com/songcity/
March 9th, 2010 at 2:19 pm
Why sulf the web? come and join us and you will find everything you can imagine from
March 22nd, 2010 at 12:24 pm
This is nice posting from you … Congrats
March 22nd, 2010 at 1:40 pm
nice article and also nice all the site … congrats and keep up the good posting
March 31st, 2010 at 7:30 am
Cirebon Business Advertisement. Iklan Bisnis Cirebon adalah Direktori Usaha di kota Cirebon dan sekitarnya
May 2nd, 2010 at 4:25 am
Ìû ( txtpromotion.ru ) ïðåäîñòîâëÿåì òîëüêî êà÷åñòâåííûå óñëóãè (êîïèðàéò, ðåðàéò, ïåðåâîäû) âñå äëÿ ïðîäâèæåíèÿ âàøèõ ñàéòîâ â òîï10
June 2nd, 2010 at 10:52 pm
Great post, thanks for sharing very informative
Vegetarian Recipes’s last blog post..Delicious Veggie Omelet
July 10th, 2010 at 9:44 am
Thanks for sharing this informative and great post.
Ciupanezul’s last blog post..PreÅŸedinte pentru o zi
December 7th, 2010 at 11:57 am
Hmm this will helpful in placing advisement banners between posts. This will solve my confusion where to place banner on my blog. One of my advertiser asking me for placing his banner between his specified posts but I was unable to do that time. Thanks for this code.
December 16th, 2010 at 9:22 am
nice post..:)
thanks for sharing this great post.
blindx’s last blog post.. my dating blog