我想显示博客帖子的时间,如下所示:
“标题标题,由XYZ在1小时前发布”
我想要的是这样的时间:5分钟前,1小时前,2天前,1个月前。
我怎样才能让它工作?
我无法获得确切的wordpress API代码来实现它。请帮忙。
我想显示博客帖子的时间,如下所示:
“标题标题,由XYZ在1小时前发布”
我想要的是这样的时间:5分钟前,1小时前,2天前,1个月前。
我怎样才能让它工作?
我无法获得确切的wordpress API代码来实现它。请帮忙。
在模板中,您可以看到the_title()
, 您需要将其更改为以下内容:
echo get_the_title() . \', \' .
\'posted by \' .
get_the_author() . \', \' .
human_time_diff( get_the_time( \'U\' ), current_time( \'timestamp\' ) ) .
\' ago\';
human_time_diff()
就是那个做关于你主题的部分的人。虽然你也要求其他人。但是,如果您想让它看起来更干净,请尝试:
printf(
\'<h2>%s, posted by %s, %s ago</h2>\',
get_the_title(),
get_the_author(),
human_time_diff(
get_the_time( \'U\' ),
current_time( \'timestamp\' )
)
);
替换第一个参数中所需的任何标记/格式