WordPress.org

Ready to get started?Download WordPress

Forums

If the_date = today displays 'Today' else the_date (7 posts)

  1. Lucky-1
    Member
    Posted 5 years ago #

    It's easy to do it?
    What I want is to display Today for the today posts, Yesterday for yesterday posts and else the date of the post
    Thanks

  2. MichaelH
    Member
    Posted 5 years ago #

    This goes in the loop:

    <?php
    $days_old = (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset') *3600 ) ) / (60*60*24);
    if ($days_old <=1) {
      echo 'Today';
    } elseif ($days_old > 1 & $days_old <= 2) {
      echo 'Yesterday';
    } else {
      the_time('F jS, Y');
    }
    ?>
  3. Lucky-1
    Member
    Posted 5 years ago #

    Nice, thank you
    If I use the_date then will show just 1 time Today, and 1 time Yesterday?
    I messed to say I want that atribute of the date, just to show one time the date value

  4. MichaelH
    Member
    Posted 5 years ago #

  5. stereopoly
    Member
    Posted 4 years ago #

    I'm from germany and the time is not right for me. how can i change it to make it work for me? f.e.: posts from the late 22nd of september are shown as "today" on the 23rd... please help!

  6. 95alexander95
    Member
    Posted 4 years ago #

    MichaelH: This code work perfect, except that it displays "Today" for the posts that been posted in 24 hours. I dont want that, I want the text "Today" if it were posted the same day, not the same 24 hours. Please someone help :)

  7. 95alexander95
    Member
    Posted 4 years ago #

    Bump! I really need help. :)

Topic Closed

This topic has been closed to new replies.

About this Topic