Home » Labs » How to add AdSense after first post on WordPress  

How to add AdSense after first post on WordPress

Filed under Labs

Adding an advertisement like Google AdSense after the first post is a good idea for those who look for making money from advertisements, there are many plugins which will do this job, but its not feasible to implement plugins for every needs on site.

Here is an example of WordPress loop which will allow you to insert advertisement like Google AdSense, custom ads after the first post. It use a variable to count the number of post and when it attain the particular count will display the ad. You can insert your ads ‘in your_ad.php’.

<?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); $counter++; ?>
        // the loop stuffs
       <?php if ($counter <= 1) { include (TEMPLATEPATH . '/your_ad.php'); } ?>
    <?php endwhile; ?>
<?php else : ?>
<?php endif; ?>

Posts you may like: