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

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

PHP中文网
Release: 2016-05-25 17:14:14
Original
1284 people have browsed it

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

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;);
Copy after login

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template