返回列表 发布新帖
查看: 46|回复: 0

[代码技巧] 子比主题 – 文章页添加本站历史上的今天

[复制链接]
SunJu_FaceMall
社区贡献

315

主题

190

回帖

1万

积分

等级头衔
Icon组别 : 管理员
Icon等级 :

积分成就
   钻石 : 524 颗
   贡献 : 1457 点
   金币 : 12 枚
Icon在线时间 : 1294 小时
Icon注册时间 : 2024-11-22
Icon最后登录 : 2025-10-29

荣誉勋章

会员LV.1会员LV.2会员LV.3会员LV.4会员LV.5会员LV.6会员LV.7会员LV.8会员LV.9会员LV.10

风云·优秀版主

飞流名人堂成员

1

实名认证 手机认证 vip vip-year FLLTCN发表于 2025-10-8 17:32:08 | 查看全部 |阅读模式 浙江金华

资源无需等待,交易就趁现在,全面资源整合网络大咖云集,让你轻松玩转互联网!

您需要 登录 才可以下载或查看,没有账号?立即注册

×
给子比主题文章页面加一个本站历史上的今天,加上去可以看到去年的今天的文章,并且可以看到自己之前发的什么文章,喜欢的自行部署吧!

image.webp
代码部署
跟着我的步骤走不会有问题,一共三个地方,话不多说直接开始
func代码
我们要到:/wp-content/themes/zibll/func.php文件里面,没有这个文件自己创一个,创建之后记得加php头,将下面的代码放到里面
  1. //历史上的今天,代码来自柳城博主的 WP-Today 插件
  2. function today_in_history() {

  3.   // $title = "历史上的今天";
  4.   ?>
  5. <?php
  6.   $limit = 5;
  7.   global $wpdb;
  8.   $post_year = get_the_time('Y');
  9.   $post_month = get_the_time('m');
  10.   $post_day = get_the_time('j');
  11.   $sql = "select ID, year(post_date_gmt) as h_year, post_title, comment_count FROM
  12.     $wpdb->posts WHERE post_password = '' AND post_type = 'post' AND post_status = 'publish'
  13.         AND year(post_date_gmt)!='$post_year' AND month(post_date_gmt)='$post_month' AND day(post_date_gmt)='$post_day'
  14.         order by post_date_gmt DESC limit $limit";
  15.   $histtory_post = $wpdb->get_results($sql);
  16.   if( $histtory_post ) {
  17.     foreach( $histtory_post as $post ) {
  18.       $h_year = $post->h_year;
  19.       $h_post_title = $post->post_title;
  20.       $h_permalink = get_permalink( $post->ID );
  21.       $h_comments = $post->comment_count;
  22.       $h_post .= "<li><lable>$h_year</lable>:<a href='".$h_permalink."' style='color:blue' title='Permanent Link to ".$h_post_title."'>$h_post_title <span>($h_comments)</span></a></li>";
  23.     }
  24.   }
  25.   $arr_month = array( 1=>"一月",2=>"二月",3=>"三月",4=>"四月",5=>"五月",6=>"六月",7=>"七月",8=>"八月",9=>"九月",10=>"十月",11=>"十一",12=>"十二" );
  26.   foreach($arr_month as $key => $value) {
  27.     if($post_month == $key) {
  28.       $month_l = $value;
  29.     }
  30.   }
  31.   if ( $h_post ) {
  32.     $result = '
  33.         <section class="today-in-history">
  34.             <fieldset>
  35.                 <legend>
  36.                    <div class="today-date">
  37.                         <span class="month">'.$month_l.'</span>
  38.                         <span class="day">'.$post_day.'</span>
  39.                     </div> <h3>本站历史上的今天</h3>
  40.                 </legend>
  41.                 <ul>'.$h_post.'</ul>
  42.             </fieldset>
  43.         </section>';
  44.   } else {
  45.     $result = '<section class="today-in-history">
  46.         <fieldset>
  47.             <legend>
  48.                  <div class="today-date">
  49.                     <span class="month">'.$month_l.'</span>
  50.                     <span class="day">'.$post_day.'</span>
  51.                  </div>
  52.                  <h3>本站历史上的今天</h3>
  53.             </legend>
  54.             <ul>"吼吼~~~,往年的今天站长不知道跑哪里偷懒去了~~~"</ul>
  55.          </fieldset>
  56.         </section>';
  57.   }
  58.   echo $result;
  59. }
复制代码
css代码
直接将代码放到:子比主题–>>自定义CSS样式即可!
  1.     .today-in-history {
  2.         display: block;
  3.         position: relative;
  4.         width: 100%;
  5.         height: auto;
  6.         margin: 0 auto;
  7.         border: 0;
  8.         padding: 0;
  9.     }
  10.    
  11.     .today-in-history fieldset {
  12.         display: block;
  13.         width: 100%;
  14.         height: auto;
  15.         margin: 0 auto;
  16.         border: 1px dashed #999;
  17.         padding: 0;
  18.     }
  19.    
  20.     .today-in-history fieldset legend {
  21.         display: block;
  22.         width: auto;
  23.         height: 36px;
  24.         margin: 0 50px;
  25.         border: 0;
  26.         padding: 0;
  27.     }
  28.    
  29.     .today-in-history fieldset legend .today-date {
  30.         float: left;
  31.         display: block;
  32.         width: 36px;
  33.         height: 100%;
  34.         margin: 0 auto;
  35.         border: 0;
  36.         padding: 0;
  37.         line-height: 18px;
  38.         border-radius: 5px;
  39.         overflow: hidden;
  40.     }
  41.    
  42.     .today-in-history fieldset legend .today-date .month {
  43.         display: block;
  44.         width: 100%;
  45.         height: 50%;
  46.         margin: 0;
  47.         border: 0;
  48.         padding: 0;
  49.         font-size: 12px;
  50.         text-align: center;
  51.         color: #fff;
  52.         background: #c10e0e;
  53.     }
  54.    
  55.     .today-in-history fieldset legend .today-date .day {
  56.         display: block;
  57.         width: 100%;
  58.         height: 50%;
  59.         margin: 0;
  60.         border: 0;
  61.         padding: 0;
  62.         text-align: center;
  63.         font-size: 12px;
  64.         font-weight: bold;
  65.         color: #000;
  66.         background: #eee;
  67.     }
  68.    
  69.     .today-in-history fieldset legend h3 {
  70.         display: inline-block;
  71.         width: auto;
  72.         height: 40px;
  73.         margin: 0;
  74.         border: 0;
  75.     padding: 0 10px;
  76.         line-height: 40px;
  77.         font-size: 18px;
  78.         color:#cccc00;
  79.         background: none;
  80.     }
  81.    
  82.     .today-in-history fieldset ul {
  83.         width: auto;
  84.         height: auto;
  85.         margin: 15px 20px;
  86.         border: 0;
  87.         padding: 0;
  88.     }
  89.    
  90.     .today-in-history fieldset ul li label {
  91.         margin: 0 5px;
  92.         border: 0;
  93.         padding: 0;
  94.     }
复制代码

zib-single.php代码
我们到:/wp-content/themes/zibll/inc/functions/zib-single.php,然后搜“版权声明”,如下图放代码
tengfei_down (15).webp
游客,如果您要查看本帖隐藏内容请回复

本帖被以下淘专辑推荐:

路虽远,行则将至;事虽难,做则必成。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

飞流广播+ 发布

系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
10-30 17:02
系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
10-09 09:07
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
09-24 09:00
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
09-11 11:40
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
09-02 09:17
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
08-27 08:56
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
08-20 15:12
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
08-03 10:22
系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
06-30 08:57
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
06-18 09:14
系统消息:清风网络已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
04-11 09:40
系统消息:清风网络已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-10 09:31
系统消息:IXM77777已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-09 13:44
系统消息:清风网络已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-09 09:22
系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
04-09 08:52
系统消息:清风网络已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-08 09:24
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-07 09:02
系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
02-27 09:35
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
02-26 09:06
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
02-25 08:49
站内通告

提供资源交易、信息共享、靓号交流、技术变现、学习问答、兴趣娱乐等全面服务。

1.丰富功能系统,扩展社区特色玩法,打造最好的互联网聚集圈子。

2.准确信息真实交易,安全快捷又方便,让虚拟交易面对面。

3. 天上不会掉馅饼,话术骗术迷人心,切勿脱离平台线下交易,被骗与平台无关!

4. 欺诈骗钱,违规违法将视情受到警告&禁言&封号甚至检举至👮🏻‍♀️处理!

官方Q群:123129钉推群:BAYR2383 站长QQ:3220000000

投诉/建议/商务合作联系

fl@fllt.cn

严禁私下交易,被骗与本站无关。
违反交易细则,取证立查严惩。
  • 钉钉新帖推送群
  • 官方交流QQ群
  • 站长唯一微信号

👮曝光Ta|🧿小黑屋|📴手机页|飞流网 ( 渝ICP备2025054677号-1|电信增值许可 渝B2-20250789 )|网站地图

GMT+8, 2025-11-8 01:57 , Processed in 0.096892 second(s), 61 queries, MemCached On , Gzip On.

Based on XJ-TX X3.5 Licensed

飞流论坛 HanAnalytics icp Astro vhAstro-Theme

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表