我想展示一些关于“这个网站最后一次更新是在2019年10/11”的文字--我可以在个人页面和帖子上找到解决方案,但不能查询数据库并找到整个网站的最新更新。
我尝试过改编一些wp_query,但失败得很惨烈。
发布于 2019-09-23 03:18:37
您可以通过两种方式完成此操作:
1:您可以使用This Plugin来完成
2:如果你不想使用这个插件,你可以编辑function.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;
}https://stackoverflow.com/questions/58044623
复制相似问题