Placing AdSense ads after the first post
anomit | March 11, 2007Well, lets get to the point and admit that everybody wants to rake in some moolah from their AdSense susbscriptions. But the thing that bothers them the most would be the proper positioning of the ads. Imagine a new visitor coming to your blog to see it cluttered with misplaced ads, like one bang on top of the first post. Forget about clicking on the ad, he won’t even read your first post and there you have your potential $1 bidding you goodbye.
I got the idea of this trick from this post at Jake Jarvis’ blog. I had been on the lookout for such a thing for a long time.
In this post I will elaborate it a bit to make it easier for newbies at coding who may have difficulties finding out the start and end of loops.
The file you need to edit is index.php in most themes or like theloop.php in k2. Basically the idea is to put the ad block in the post loop. Remember that: the post loop.
Now open the required file in the Theme Editor from your wordpress admin and find the beginning of the post loop, the line containing if(have_posts()).
For example, in theloop.php you will find it in this manner:
if ( have_posts() ) {
Freshy makes life a bit easier for you, by including descriptions in the index.php file. Find out
<!--blog-->
Now that you have found this line, below this line declare a variable:
<?php $count = 1; ?>
Now go to the end of the post loop, to be understood by codes like
<?php endif; ?>
. After this line of code and just before the closure of the
</div>
tag, add this loop:
<?php if ($count == 1) : ?> <!-- YOUR ADSENSE CODE HERE --> <?php endif; $count++; ?>
Now placing the adsense code becomes easier if you are using the AdSense Deluxe plugin. It keeps the coding neat. Just put in the following line of code in the loop:
<?php adsense_deluxe_ads('Ad_Name'); ?>
and you are done!!






