wordpress   发布时间:2022-05-06  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了WordPress教程:超过一定时间的老文章顶部显示自定义信息大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

站长朋友们在wordpress插件库查找插件时,偶尔会看到提示插件已经超过 2 年没有更新。如果我们想在自己的wordpress文章顶部显示类似的提示信息,比如超过 1 年没有更新的文章,就提示某些信息,如下图所示:

WordPress教程:超过一定时间的老文章顶部显示自定义信息

这篇wordpress教程里,我们就向大家介绍一下实现的方法。切换到主题目录,打开 functions.PHP 文件,加入以下代码

Crayon-5c891cbd7fca2229907978" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHP
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
'.$content; } return $content; } add_filter( 'the_content','old_content_message' );
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891cbd7fca2229907978-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cbd7fca2229907978-2">2
Crayon-num" data-line="Crayon-5c891cbd7fca2229907978-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cbd7fca2229907978-4">4
Crayon-num" data-line="Crayon-5c891cbd7fca2229907978-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cbd7fca2229907978-6">6
Crayon-num" data-line="Crayon-5c891cbd7fca2229907978-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cbd7fca2229907978-8">8
Crayon-num" data-line="Crayon-5c891cbd7fca2229907978-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891cbd7fca2229907978-10">10
Crayon-num" data-line="Crayon-5c891cbd7fca2229907978-11">11
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891cbd7fca2229907978-1">Crayon-c">//超过一定时间的文章顶部显示自定义信息
Crayon-line Crayon-striped-line" id="Crayon-5c891cbd7fca2229907978-2">Crayon-t">functionCrayon-h"> Crayon-e">old_content_messageCrayon-sy">(Crayon-v">$contentCrayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891cbd7fca2229907978-3">Crayon-h"> Crayon-v">$modifiedCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_the_modified_timeCrayon-sy">(Crayon-s">'U'Crayon-sy">)Crayon-sy">;Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891cbd7fca2229907978-4">Crayon-h"> Crayon-v">$currentCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">current_timeCrayon-sy">(Crayon-s">'timestamp'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891cbd7fca2229907978-5">Crayon-h"> Crayon-v">$diffTimeCrayon-h"> Crayon-o">=Crayon-h"> Crayon-sy">(Crayon-v">$currentCrayon-h"> Crayon-o">-Crayon-h"> Crayon-v">$modifiedCrayon-sy">)Crayon-h"> Crayon-o">/Crayon-h"> Crayon-sy">(Crayon-cn">60Crayon-o">*Crayon-cn">60Crayon-o">*Crayon-cn">24Crayon-sy">)Crayon-sy">;Crayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891cbd7fca2229907978-6">Crayon-h"> Crayon-st">ifCrayon-sy">(Crayon-v">$diffTimeCrayon-h"> Crayon-h"> Crayon-cn">365Crayon-h"> Crayon-sy">)Crayon-sy">{
Crayon-line" id="Crayon-5c891cbd7fca2229907978-7">Crayon-h"> Crayon-v">$contentCrayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'
Crayon-sy">.Crayon-e">get_the_modified_timeCrayon-sy">(Crayon-s">'Y年n月j日'Crayon-sy">)Crayon-sy">.Crayon-s">',已超过 1 年没有更新,如果文章内容失效,请反馈给我们,谢谢!
'Crayon-sy">.Crayon-v">$contentCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cbd7fca2229907978-8">Crayon-h"> Crayon-sy">}
Crayon-line" id="Crayon-5c891cbd7fca2229907978-9">Crayon-h"> Crayon-k ">returnCrayon-h"> Crayon-v">$contentCrayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891cbd7fca2229907978-10">Crayon-sy">}
Crayon-line" id="Crayon-5c891cbd7fca2229907978-11">Crayon-e">add_filterCrayon-sy">(Crayon-h"> Crayon-s">'the_content'Crayon-sy">,Crayon-h"> Crayon-s">'old_content_message'Crayon-h"> Crayon-sy">)Crayon-sy">;

大佬总结

以上是大佬教程为你收集整理的WordPress教程:超过一定时间的老文章顶部显示自定义信息全部内容,希望文章能够帮你解决WordPress教程:超过一定时间的老文章顶部显示自定义信息所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: