Zibll主题给刚发布和刚更新的文章分别加上”新””更”小图标及文字提示—(第二版)1年前发布142490 支持Zibll子比的最新版本: 本文达到的效果如下: 如果是24小时内发布:显示“新”图标,标题显示1天内发布。 如果是24小时内更新:显示“更”图标,标题显示1天内更新。 如果不是24小时内发布或者更新:不显示任何图标,标题显示最近更新日期。 效果图 教程开始: 第一、解决wordpress时区问题,否则可能会显示不正确,需要有PHP.INI编辑权限,以宝塔PHP8.1为例。 php.ini配置文件,大概在968行,或则搜索date.timezone,看=后面的值是什么,如果是PRC则不改动,如果不是,修改为PRC,修改后重启PHP。 网站根目录下wp-config.php,第一行添加 date_default_timezone_set(‘PRC’); wordpress后台设置-常规中,时区、日期、时间,按如下设置。 第二、Zibll主题设置—文章&列表—列表卡片模式,将“首页列表 卡片模式“关闭。 PS:主要是卡片模式调试了好久,NEW小图标一直错位,无奈关闭。 第三、修改主题目录中的/inc/functions/zib-posts-list.php文件,找到以下代码: //获取文章列表的标题 function zib_get_posts_list_title($class = 'item-heading') 将整段代码修改为: //获取文章列表的标题 function zib_get_posts_list_title($class = 'item-heading') { $get_permalink = get_permalink(); $_post_target_blank = _post_target_blank(); $title = get_the_title() . get_the_subtitle(true,'focus-color'); $t1=get_the_time('Y-m-d h:i:s',isset($post)); $t2=wp_date('Y-m-d h:i:s'); $t3=get_the_modified_time('Y-m-d h:i:s'); $diff1=(strtotime($t2)-strtotime($t1))/3600; $diff2=(strtotime($t2)-strtotime($t3))/3600; $icon_html = ''; if ($diff1 < 24) { $icon_html = '<span class="new-icon"></span>'; // 新发表文章 $html = '<h2 class="' . $class . '">' . $icon_html . '<a' . $_post_target_blank . ' href="' . $get_permalink . '">' . $title . '<font color="red">【1天内发布】</font></a></h2>'; return $html; } elseif ($diff2 < 24) { $icon_html = '<span class="update-icon"></span>'; // 更新的文章 $html = '<h2 class="' . $class . '">' . $icon_html . '<a' . $_post_target_blank . ' href="' . $get_permalink . '">' . $title . '<font color="red">【1天内更新】</font></a></h2>'; return $html; } else { $html = '<h2 class="' . $class . '">' . $icon_html . '<a' . $_post_target_blank . ' href="' . $get_permalink . '">' . $title . '<font color="red">【更新于'. $t3 . '】</font></a></h2>'; return $html; } } 代码注释: diff1<24,diff2<24,24代表1天,如果显示2天则修改为48,以此类推。 第四、添加CSS样式 后台主题设置-全局功能-自定义代码-自定义CSS样式插入 此处内容已隐藏,请评论后刷新页面查看. 温馨提示:本文最后更新于2023-12-24 12:34:45,某些文章具有时效性,若有错误或已失效,请私信客服或联系知新社长。 © 版权声明文章版权归作者所有,未经允许请勿转载。 四月 12 知岛上的今时往日 "吼吼~,往年的今天,作者不知道跑哪里偷懒去了~" THE END子比主题教程之家网站/配置/代码# 代码# 主题# 子比主题# 标题 喜欢就支持一下吧点赞0 分享QQ空间微博QQ好友海报分享复制链接收藏3