Sometime we may need to add an advertisement or adsense ads after our first post. That is quite easy to do. However, how if we want to add multiple advertisements after certain number of posts? See how it can be done..
- First open your themes index.php file using any of your favorite editor.
- Find the following code of line:
<?php if(have_posts()) : ?>
- Copy the code below and paste it before the above code.
<?php $postnum = 1; $showads1 = 1; $showads2 = 2; ?>
- Scroll more down the index.php page and find the following the code of line:
<?php endwhile; ?>
- Same procedure, copy and paste the code below before the code above.
<!--Ads Code Start Here--!>
<?php if ($postnum == $showads1) { include (TEMPLATEPATH . '/ads1.php'); } ?>
<?php if ($postnum == $showads2) { include (TEMPLATEPATH . '/ads2.php'); } ?>
<?php $postnum++; ?>
<!--Ads Code End Here--!>
- Finally, create two files named as ads1.php and ads2.php and paste any advertisement code into both the files. Not only advertisement actually. You can try to insert anything, really.
- Make sure to put both files into the same directory as the index.php file.
The code above will display ads after the first and second post. By changing the $showads1=1 and $showads2=2 number into “2” or “3” will give different position of advertisement. Try with different combination to get anywhere you want the ads to appear.
Best example is that you can see after my first post, there are two rows of section (popular posts and subscription section).
Now, enjoy!

