在此更新版本中meks_time_ago()
, 如果发布日期小于$threshold
几天前的。否则,将返回完整日期和硬币。
function meks_time_ago( $days_threshold = 3 ) {
$published_date_timestamp = get_the_time( \'U\' );
$current_date = new DateTime();
$published_date = new DateTime( "@$published_date_timestamp" );
$interval = $published_date->diff( $current_date );
$interval = intval( $interval->format( \'%a\' ) );
// If the post was published more than the $threshold of days ago,
// show the published date and time.
if ( $interval > $days_threshold ) {
return sprintf( \'%s %s %s\',
get_the_date(),
__( \'at\', \'text-domain\' ),
get_the_time()
);
} else {
// Otherwise, use the human readable time.
return sprintf( \'%s %s\',
human_time_diff( $published_date_timestamp, $current_date->getTimestamp() ),
__( \'ago\', \'text-domain\' )
);
}
}