• How to have Adsense appear under the first post in Wordpress blog?

    Posted on October 28th, 2008 admin No comments

    Following is what I learned recently on having Adsense codes only appear after the first post in Wordpress blog and nowhere else.

    Open the index.php file and search for the following lines:

    <!–p if (have_posts()) –>
    <!–p $postCount=0;–>
    <!–p while (have_posts()) : the_post(); $loopcounter++–>
    <!–p $postCount++–>

    Add the following above these lines:

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


    After that search for the following lines in the same index.php file:

    <?php if ($loopcounter == 1) { include (TEMPLATEPATH . ‘/ad_middle.php’); } ?>
    </div>
    *** Take note about this gap ***
    <?php endwhile; ?>

    Add the following scripts into the gap:

    <?php if ($postnum == $showadsense1) {
    echo ‘

    *** Put your Adsense Script here ***
    ‘;

    } ?>

    <?php $postnum++; ?>

    By the way, this version of Wordpress I use is Wordpress 2.6.3. Not sure if other version of Wordpress are having the same coding in index.php or not … Anyway, worth a try.

    Leave a reply