http://codex.wordpress.org/Function_Reference/human_time_diff
我正在使用human_time_diff()
输出WordPress帖子的相对日期。
echo human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ago';
这将输出类似的东西
34 mins ago
如何更改措辞以显示完整的单词"分钟"?例如
34 minutes ago
我在寻找相同答案时发现了您的问题。我做了一个函数,让我用这个简单的代码块整齐地调用human_time_diff
:<?php human_friendly_date(); ?>
。问题的答案在倒数第二行代码中。
function human_friendly_date() {
global $post;
$today = date("r");
$postdate = get_the_time('r');
$difference = round((strtotime($today) - strtotime($postdate))/(24*60*60),0);
if ($difference >= 7) {
$humandate = the_time('F j, Y');
} else {
$humandate = human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';
}
$humandate = str_replace('mins', 'minutes', $humandate);
echo $humandate;
}