子比美化-添加底部统计信息模块小工具

介绍

分享一下子比的底部横向网站统计的模块,有博客播报、文章统计、浏览统计,用起来非常美观而且还非常实用的一个底部美化!!!不知道原创是谁,网上的资源整理测试的。

图片展示

图片[1],子比美化-添加底部统计信息模块小工具

教程开始

注意注意要在子比主题的主题目录下,header.php底部添加以下函数代码:

<!--统计信息函数-->
<script type="text/javascript" >
<?php
//用户总数
$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");echo "var tj_jstext="."'$users'";
?>
</script>
<script type="text/javascript" >
<?php
/*
 * WordPress获取今日发布文章数量
 *www.zxiyun.com
 */
function nd_get_24h_post_count(){
  $today = getdate();
  $query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"]);
  $postsNumber = $query->found_posts;
  return $postsNumber;
}
$post_24h = nd_get_24h_post_count();
echo "var tj_24h="."'$post_24h'";
?>
</script>
<script type="text/javascript" >
<?php
/*
 * WordPress整站文章访问计数
 *www.zxiyun.com
 */
function nd_get_all_view(){
  global $wpdb;
  $count=0;
  $views= $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key='views'");
  foreach($views as $key=>$value){
    $meta_value=$value->meta_value;
    if($meta_value!=' '){
      $count+=(int)$meta_value;
    }
  }return $count;
}
$post_view = nd_get_all_view();
echo "var tj_view="."'$post_view'";
?>
</script>
<script type="text/javascript" >
<?php
//日志总数
$count_posts = wp_count_posts(); 
$published_posts =$count_posts->publish;
echo "var tj_rzzs="."'$published_posts'";
?>
</script>
<script type="text/javascript" >
<?php
//稳定运行
$wdyx_time = floor((time()-strtotime("2024-3-30"))/86400);
echo "var tj_wdyx="."'$wdyx_time'";
?>
</script>

下面是HTML+js代码,至于放在哪,【外观】【小工具】【自定义HTML】【首页底部全宽度】,不想多说了。(注意修改内容)

<div id="wiiuii-info-wg-mian">
  <div class="wiiuii-info-item">
    <div class="wiiuii-yxsj-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#iconxiuxiyixia"></use>
      </svg>
      <span class="wiiuii-i-num"
        ><script type="text/javascript">
          document.write(tj_wdyx);
        </script></span
      >
      <p>运行时间</p>
    </div>
    <div class="wiiuii-yhzs-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#iconzhanghuguanli"></use>
      </svg>
      <span class="wiiuii-i-num"
        ><script type="text/javascript">
          document.write(tj_jstext);
        </script></span
      >
      <p>用户总数</p>
    </div>
    <div class="wiiuii-llzs-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#iconyanjing"></use>
      </svg>
      <span class="wiiuii-i-num"
        ><script type="text/javascript">
          document.write(tj_view);
        </script></span
      >
      <p>浏览总数</p>
    </div>
    <div class="wiiuii-wz-item">
      <div class="wiiuii-wz-sty wiiuii-wzzs-item">
        <svg class="icon fa-2x" aria-hidden="true">
          <use xlink:href="#iconxiezuoye"></use>
        </svg>
        <span class="wiiuii-i-num"
          ><script type="text/javascript">
            document.write(tj_rzzs);
          </script></span
        >
        <p>文章总数</p>
      </div>
      <div class="wiiuii-wz-sty wiiuii-jrfb-item">
        <svg class="icon fa-2x" aria-hidden="true">
          <use xlink:href="#iconaixin"></use>
        </svg>
        <span class="wiiuii-i-num"
          ><script type="text/javascript">
            document.write(tj_24h);
          </script></span
        >
        <p>今日发布</p>
      </div>
    </div>
    <div class="wiiuii-sjcs-item">
      <div class="wiiuii-sjcj-m">
        <span style="font-size: 30px">今天是</span>
        <div id="wiiuii-date-text"></div>
        <div id="wiiuii-week-text"></div>
        <div class="wiiuii-meo-item">
          <style>
  @keyframes gradientAnimation {
    0% {
      background-position: 0% 50%;
    }
    100% {
      background-position: 100% 50%;
    }
  }

  .dynamic-gradient-text {
    font-size: 48px;
    background: linear-gradient(270deg, red, orange, yellow, green, blue, indigo, violet);
    background-size: 800% 800%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-fill-color: transparent;
    animation: gradientAnimation 10s ease infinite;
  }
</style>
<body>

<span style="font-size: 20px" class="dynamic-gradient-text">欢迎光临Axing的Blgo</span>
</body>
        </div>
        <div class="wiiuii-sjcj-content">
          <span id="wiiuii-fatalism"></span>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
$(function () {
  var myDate = new Date();
  var year = myDate.getFullYear(); //获取当前年
  var mon = myDate.getMonth() + 1; //获取当前月
  var date = myDate.getDate(); //获取当前日
  var week = myDate.getDay();
  var weeks = [
    "星期日",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六"
  ];
  $("#wiiuii-date-text").html(year + "年" + mon + "月" + date + "日");
  $("#wiiuii-week-text").html(weeks[week]);
  if (week > 0 && week < 5) {
    $("#wiiuii-fatalism").html("再坚持" + (5 - week) + "天就到周末啦!");
  } else if (week === 5) {
    $("#wiiuii-fatalism").html("啊啊啊,明天就是周末啦!");
  } else {
    $("#wiiuii-fatalism").html("今天是周末,好好休息一下吧!");
  }
  $("#wiiuii-meos").attr(
    "src","https://obohe.com/i/2022/04/22/expression-" + week + ".png"
  );
});
$("#wiiuii-info-wg-mian").parents(".zib-widget").css({
  padding: "0",
  background: "none"
});
</script>

将下面引用图标js代码放在后台自定义代码→自定义底部HTML代码这里就可以了。

下面是CSS代码,原本一起放的,但是CSS Grid布局不兼容WP的自定义工具,所以就只能放在主题后台的【自定义CSS样式】里面咯!

© 版权声明
THE END
喜欢就支持一下吧
点赞6赞赏 分享
评论 共7条

请登录后发表评论

    • 热门评论
      Axing的头像,Axing博客永久会员(资源下载无上限)Axing徽章-人气大使,Axing博客等级-LV10,Axing博客作者0