Forums

Adsense on WordPress Posts and Pages written in year 2011 (5 posts)

  1. vineetsharma1986
    Member
    Posted 1 year ago #

    Hi... I want to show adsense ads only on those posts and pages which are written in the year 2011. It there any way of doing it in wordpress ?

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    use a conditional statement in the loop;

    example:

    <?php if( get_the_time('Y') == 2011 ) { ?>
    /*ADS CODE HERE*/
    <?php } ?>

    http://codex.wordpress.org/Function_Reference/get_the_time

  3. vineetsharma1986
    Member
    Posted 1 year ago #

    How can I do it outside the loop ?

  4. alchymyth
    The Sweeper
    Posted 1 year ago #

    from: http://codex.wordpress.org/Function_Reference/get_the_time

    Returns the time of the post with ID $post->ID in the WordPress default format.

    <?php echo get_the_time('', $post->ID); ?>

    details will depend on how you included the adsense in the first place;

    and it will only make sense on a single post page; example:

    <?php if( is_single() && get_the_time('Y', $post->ID) == 2011 ) { ?>
    /*ADS CODE HERE*/
    <?php } ?>
  5. vineetsharma1986
    Member
    Posted 1 year ago #

    thanks it works now :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags