有时候发现别人的网站有提示文章时间久了过期了的显示,而用户发现文章内容失效了想反馈,但是不知道在哪反馈?没关系,快把本文提供的文章更新于何年何月或过期失效提示代码放上去吧。
实现方法
实现方法非常简单,只需将下面的代码加入到主题目录下 functions.php 文件中即可,提示的内容可以修改成自己想要的信息。
/*文章过期提示 开始*/
function article_time_update() {
date_default_timezone_set('PRC');
$newdate=time();
$updated_date = get_the_modified_time('Y-m-d H:i:s');
$updatetime=strtotime($updated_date);
$custom_content = '';
if ( $newdate > $updatetime+86400) {
$custom_content= '<style>.article-timeout{ color: #8a6d3b;
border-color: #faebcc;margin-bottom:20px;
background-color: #fcf8e3;border-radius:8px;padding:10px 10px;}</style><div class="article-timeout"><strong><i class="fa fa-bell" aria-hidden="true"></i> 温馨提示:</strong>本文最后更新于<code>'. $updated_date . '</code>,某些文章具有时效性,若有错误或已失效,请在文末评论区<a href="#comment">留言</a></div >';
}
echo $custom_content;
}
add_action('zib_posts_content_before','article_time_update');
/*文章过期提示 结束*/
updatetime+86400的86400是时间秒的数字,这个时间很短的,建议三个月为准:updatetime+7884000,这样短期文章肯定很难过期,3个月就不一定了,如果想更多的时间,自己去网上找计算器来换算就行了,精确到多少秒。
文末评论区<a href=”#comment”>留言</a>,如果没有开启留言的话,直接贴上能联系到的链接即可。<a href=”https://www.bailuze.com/about”>联系我们</a>。
实现位置
Zibll子比主题functions.php文件所在的位置:/wp-content/themes/zibll/functions.php
为了防止在线更新主题的时候,functions.php文件的内容被覆盖,我们也可以将上面的代码改成放到func.php文件中。
如果想把温馨提示放到文章内容尾部显示,只需将上面代码中的zib_posts_content_before改成zib_posts_content_after即可。
效果图

👋 感谢您的观看!
© 版权声明
THE END