方法1:
效果:
打开functions.php
,加入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//添加老文章提示信息 function old_content_message($content) { $modified = get_the_modified_time('U'); $current = current_time('timestamp'); $diffTime = ($current - $modified) / (60 * 60 * 24); global $wp; $current_url = home_url(add_query_arg(array(),$wp->request)); if ($diffTime > 365 and !strstr($current_url, "feel") ) { $content = $content.'<div class="warn">本文最后更新于'.get_the_modified_time('Y年n月j日'). ',已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!</div>'; } return $content; } add_filter('the_content', 'old_content_message'); |
CSS效果:
1 |
.old-message{padding:10px;color: #DB7C22;font-size: 14px;background: #FFFCEF;border: solid 1px #FFBB76;border-radius: 2px;box-shadow: 0 0 3px #ddd;} |
方法2(推荐):
functions.php
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//添加老文章提示信息 function old_content_message($content) { $modified = get_the_modified_time('U'); $current = current_time('timestamp'); $diffTime = ($current - $modified) / (60 * 60 * 24); global $wp; $current_url = home_url(add_query_arg(array(),$wp->request)); if ($diffTime > 365 and !strstr($current_url, "feel") ) { $content = $content.'<div class="warn">本文最后更新于'.get_the_modified_time('Y年n月j日'). ',已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!</div>'; } return $content; } add_filter('the_content', 'old_content_message'); |
如果想出现在文章开头,则改为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//添加老文章提示信息 function old_content_message($content) { $modified = get_the_modified_time('U'); $current = current_time('timestamp'); $diffTime = ($current - $modified) / (60 * 60 * 24); global $wp; $current_url = home_url(add_query_arg(array(),$wp->request)); if ($diffTime > 365 and !strstr($current_url, "feel") ) { $content = '<div class="warn">本文最后更新于'.get_the_modified_time('Y年n月j日'). ',已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!</div>'.$content; } return $content; } add_filter('the_content', 'old_content_message'); |
CSS:
1 2 3 4 5 6 7 8 9 10 |
/* 提醒 */ .warn { color: #ad9948; background: #fff4b9 url(img/warn.png) -1px -1px no-repeat; border: 1px solid #eac946; overflow: hidden; margin: 10px 0; padding: 15px 15px 15px 35px; font-size: 14px; } |
本文最后更新于2023年6月6日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!