Forums

How to only display DATE POSTED on recent posts (2 posts)

  1. paul3463
    Member
    Posted 2 years ago #

    I would like to display the posted date only on recent posts - for example: either the most recent 7 posts or posts that were posted in the last 5 days. These numbers are just examples.

    Older posts would then display - both on the blog and single post layout - with NO DATE - it would be impossible for someone to see when it was posted just by looking at the post.

    I am sure this is possible. I think that it must require a conditional statement to select the posts before deciding whether to display the date information.

    I'm just not sure exactly how. My blog is at http://www.pwenglish.co.uk

    I would be grateful for help. Thanks Paul

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Have to use this is a loop

    <?php
    $mylimit=5 * 86400; //5 days * seconds per day
    $post_age = date('U') - mysql2date('U', $post->post_date_gmt);
    if ($post_age < $mylimit) {
      the_time('F j, Y');
    }
    ?>

    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

Topic Closed

This topic has been closed to new replies.

About this Topic