查询按日期排序的帖子,限制显示1篇帖子,然后获取日期。
$args = array(
\'posts_per_page\' => 1,
\'orderby\' => \'date\',
\'order\' => \'DESC\'
);
$lastpost = get_posts($args);
echo $lastpost[0] -> post_date;
编辑最后一行以正确显示:
$lastpostdate = $lastpost[0] -> post_date;
echo \'<div class="lastpostdate>"\' . $lastpostdate . \'</div>\';
或者,如果您已经有了默认顺序的查询,您可以从中获取最后一篇文章的日期:
// assuming $myquery is your query
$lastpostdate = $myquery -> posts[0] -> post_date;
或者,如果尚未更改全局查询,请在存档中使用:
$lastpostdate = $wp_query -> posts[0] -> post_date;