My Computer Back in Service

"Make Your Computer Smile Again!"

happyscreen.JPG

How To Put AdSense Ads After A Single Post per Page

Do use AdSense on your Blog? Do you want to put some Ads after your posts but are limited by the fact that you can only have 3 instances of AdSense per page? Do you want to know how to show AdSense Ads after a certain post and not others to be sure you stay within Googles guidelines and not be banned?

Here’s how you can set up an AdSense campaign to show after one post per page. The example has the Ads showing after the second post, but you can set it up after any post number you like. And this also works on Category and “Next” pages without any other changes being made to your code.

Go to your index.php in the Presentation folder of your WordPress Dashboard.

And look for:

<?php if (have_posts()) :? >
  <?php $postCount=0; ?>
  <?php while (have_posts()) : the_post();?>

And IMMEDIATELY BEFORE it put this bit of code:

<?php
$postnum = 1;
$showadsense1 = 2;
?>

Go a little further down in the code and look for this (at the end of the content statement)

<?php endwhile; ?>

And place this bit of code RIGHT BEFORE that statement:

<?php
 if ($postnum == $showadsense1)
  (your AdSense code  goes here)
$postnum++;
?>

It’s as simple as that. There should be no need to make any changes if and when you update your WordPress version, but you will have to remember to redo the code if you change your Theme.

You should be able to copy/paste the above code with no problems, just remember to put YOUR AdSense code in place of “(your AdSense code goes here)” or it will never work.

Questions or problems can be left in comments and I will answer them there so others will know the answer to your question too.



  • From the Archives

  • Subjects

  • Look-up Posts by Date

    February 2008
    S M T W T F S
    « Jan   Mar »
     12
    3456789
    10111213141516
    17181920212223
    242526272829