根据不同时间显示时间戳的最佳方法是什么?
如果在24小时内发布帖子"在{时间}"发布,否则如果帖子超过24小时显示"发布在{date}",否则如果帖子被修改,则显示"更新{modified_date}"
有什么建议吗?到目前为止我已经做到了这一点:
function ci_posted() {
$time_string = '<time itemprop="datePublished" content="%2$s" class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time itemprop="datePublished" content="%2$s" class="entry-date published" datetime="%1$s">%2$s</time><time itemprop="dateModified" content="%4$s" class="updated" datetime="%3$s">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$time_posted = esc_html( get_the_time() );
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
$posted_on = sprintf(
_x( '%s', 'post date', 'ci' ),
'' . $time_string . ''
);
if ($u_modified_time >= $u_time + 86400){
echo '<span class="posted-on"> Updated ' . $posted_on . ' at ' . $time_posted . '</span>';
} else {
echo '<span class="posted-on"> Posted at ' . $time_posted . '</span>';
}