0

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
4

1 回答 1

1

我在寻找相同答案时发现了您的问题。我做了一个函数,让我可以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;
}
于 2013-12-10T21:39:59.257 回答