根据the Codex page for get_the_time()
, 它需要在循环中使用。两者之间的区别the_time()
和get_the_time()
是前者吗echo()
es日期,后者返回日期。
有几个函数可以实现我认为您需要的功能--获取帖子的最后更新日期和时间:get_the_modified_time()
和get_the_modified_date()
. 看起来它们也需要用于The Loop.
这里有一种方法可以获取您网站中最新帖子的更新日期:
<?php
$args = array(
\'orderby\' => \'post_modified\',
\'numberposts\' => 1,
);
$myposts = get_posts( $args );
if( have_posts() ) {
while( have_posts() ) {
the_post();
$last_update = get_the_modified_date();
}
}
echo( "Last modified on $last_update." );
?>
如果您确定需要在任何循环之外,您可以始终使用
$wpdb
:
<?php
global $wpdb;
$sql = "SELECT post_modified
FROM $wpdb->posts
WHERE post_type=\'post\'
AND post_status=\'publish\'
ORDER BY post_modified DESC
LIMIT 1";
$last_update = $wpdb->get_var( $sql );
echo( "Last updated $last_update." );
?>