前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WordPress更新文章 显示最近更新时间

WordPress更新文章 显示最近更新时间

作者头像
残浔
发布2023-05-11 19:48:45
6220
发布2023-05-11 19:48:45
举报
文章被收录于专栏:UQUQUQUQ

有些资源站文章具有时效性,文章添加一个最近更新时间,提示文章最近更新的时间。 没有修改或当天修改过的文章不显示,其他的时间修改更新文章就显示提示文章最近更新时间。

代码语言:javascript
复制
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('Y年m月d日 G:i:s');
		$custom_content .= '<p>本文最后更新于:'. $updated_date . '</p>';
	} 

    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

以上代码需要添加到 functions.php

上面那个没有CSS美化 单纯文本 需要美化请自行添加样式 子比主题可以使用下面的代码进行美化

代码语言:javascript
复制
<?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('Y年m月d日 G:i:s');
		$custom_content .= '<div class="wp-block-zibllblock-alert alert-dismissible fade in"><div class="alert jb-blue">最近更新:'. $updated_date . '</div></div>';
	} 

    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

子比主题为了防止更新后失效 请在目录内新建func.php 文件 插入上方代码即可

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年5月1日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 有些资源站文章具有时效性,文章添加一个最近更新时间,提示文章最近更新的时间。 没有修改或当天修改过的文章不显示,其他的时间修改更新文章就显示提示文章最近更新时间。
  • 上面那个没有CSS美化 单纯文本 需要美化请自行添加样式 子比主题可以使用下面的代码进行美化
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档