残浔的小窝 残浔的小窝
  • 首页
  • 日常
  • 折腾
  • Centos
  • C语言
  • 网工
  • Python
  • 娱乐
  • 工具
  • 邻居
  • 服务器运行状态
  • 关于我

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

残浔
3 年前

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

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美化 单纯文本 需要美化请自行添加样式
子比主题可以使用下面的代码进行美化

<?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 文件 插入上方代码即可

2
残浔
何以解忧,唯有暴富!

评论 (2)

取消
  • Jone

    好家伙,typecho可以吗

    3 年前 回复
    • 残浔

      @Jone 你看看ty官方函数试试

      3 年前 回复

残浔

何以解忧,唯有暴富!
180
文章
27
评论
1
获赞

热门文章

TOP1
HK1 Box刷入openwrt教程+改良散热|性能远超N1盒子
3 年前
TOP2
LNMP安装以及设置防CC 防火墙
3 年前
TOP3
快速通过武软E学堂公选课教程
4 年前
  • 本站由暗云提供技术支持
  • 邻居
  • 服务器状态监控
Copyright © 2022-2025 残浔的小窝. 鄂ICP备20012530号-3 鄂公网安备42092302000067号
  • 搭建4
  • 威联通4
  • 考试3
  • 服务器3
  • OSPF3
  • 首页
  • 日常
  • 折腾
  • Centos
  • C语言
  • 网工
  • Python
  • 娱乐
  • 工具
  • 邻居
  • 服务器运行状态
  • 关于我