在网站范围内使用'last modified',而不是在特定页面/帖子上使用



我想显示一些类似于"本网站最后更新于 10/11/2019" 的文本 - 我可以找到在单个页面和帖子上执行此操作的解决方案,但不是查询数据库并在整个站点上找到最新更新的内容。

我曾试图改编一些wp_query但惨遭失败。

你可以通过以下方式做到这一点:
1:你可以通过使用这个插件
来做到这一点 2:如果你不想使用这个插件,你可以编辑函数.php文件在那里添加这个代码

function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a'); 
$custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';  
} 
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

此代码检查帖子的发布日期和上次修改日期是否不同。如果是,则在帖子内容之前显示上次修改日期。

您可以添加CSS以使其看起来更好

.last-updated {
font-size: small;
text-transform: uppercase;
background-color: #fffdd4;
}

最新更新