• Resolved 95alexander95

    (@95alexander95)


    hey!

    I have a problem. I have this code to get the text “Today” to show up if the post is posted the same day. The problem is, that it displays the text today for posts that were posted less than 24 hours ago, not the same date. So how can I get this to work. I want “today” to show up if the post is posted on the same date as today.

    <?php
    $days_old = (current_time(timestamp) – get_the_time(‘U’) – (get_settings(‘gmt_offset’) *3600 ) ) / (60*60*24);
    if ($days_old <=1) {
    echo “<img src=’Today!’>”;
    } elseif ($days_old > 1 & $days_old <= 2) {
    echo ‘Yesterday!’;
    } else {
    the_time(‘F jS, Y”);
    }
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • if you don’t care about showing the ‘yesterday’ bit as well, then the code could be:

    <?php
    if( date('Yz') == get_the_time('Yz') ) {
    echo 'today';
    } else {
    the_time('F jS, Y');
    };
    ?>
    Thread Starter 95alexander95

    (@95alexander95)

    Thank you so much! ??

    Thread Starter 95alexander95

    (@95alexander95)

    Hmm, i live in sweden, and the time doesnt seem to be right. Its 21 minutes over 12 (in the middle of the night) and the “Today” hasnt changed. How can I fix this?

    <?php
    if( date('Yz') == get_the_time('Yz') ) {
    echo 'today';
    } else {
    the_time('F jS, Y');
    };
    ?>
    Thread Starter 95alexander95

    (@95alexander95)

    does date(‘Yz’) have something to do with that?

    Thread Starter 95alexander95

    (@95alexander95)

    Hey guys! I found the soloution. ??

    I went inte the source code to a file called “WP-Settings.php” and changed -> date_default_timezone_set( ‘UTC’ ); <- to date_default_timezone_set( ‘Europe/Stockholm’ ); which is my local time.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display text “Today” if posted today.’ is closed to new replies.