Home >php教程 >PHP源码 >Wordpress显示新增文章的时间格式为“几分钟”前

Wordpress显示新增文章的时间格式为“几分钟”前

PHP中文网
PHP中文网Original
2016-05-25 17:14:141261browse

有点像微博的样式,发布日期显示为“几秒前”,“几分钱”,“几小时前”的格式。

function timeago() {
    global $post;
    $date = $post->post_date;
    $time = get_post_time('G', true, $post);
    $time_diff = time() - $time;
    if ( $time_diff > 0 && $time_diff < 24*60*60 )
        $display = sprintf( __(&#39;%s ago&#39;), human_time_diff( $time ) );
    else
        $display = date(get_option(&#39;date_format&#39;), strtotime($date) );

    return $display;
}

add_filter(&#39;the_time&#39;, &#39;timeago&#39;);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn