95alexander95
Member
Posted 1 year ago #
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'');
}
?>
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');
};
?>
95alexander95
Member
Posted 1 year ago #
95alexander95
Member
Posted 1 year ago #
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');
};
?>
95alexander95
Member
Posted 1 year ago #
does date('Yz') have something to do with that?
95alexander95
Member
Posted 1 year ago #
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.