WordPress.org

Ready to get started?Download WordPress

Forums

Adding AdSense to newest entry only (3 posts)

  1. mbalara
    Member
    Posted 8 years ago #

    Hi all. I'm a PHP idiot, so a little help goes a long way by me. I'm trying to add AdSense to my page, but I only want one ad block to appear under the newest entry on my home page, i.e. under the first/top entry and nowhere else.

    The way I imagine it is (in plain English):

    If this is newest entry then
    show AdSense code here
    else
    do nothing

    Can anyone translate that into functional PHP?

  2. makemead
    Member
    Posted 8 years ago #

    That's exactly what I do on my site: http://www.imaginekitty.com


    <?php if (have_posts()) : ?>
    <?php $count = 0; ?>

    ***stuff that shows your articles***

    <?php
    if ( $count == 0 ) {
    ?>

    ***Adsense code here***

    <?php }
    $count ++; ?>

  3. Mark (podz)
    Support Maven
    Posted 8 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic