给子比主题加一个不一样的统计模块

给子比主题加一个不一样的统计模块

先看效果

效果1

图片[1]-给子比主题加一个不一样的统计模块

效果2

图片[2]-给子比主题加一个不一样的统计模块

手机端效果

图片[3]-给子比主题加一个不一样的统计模块

因为审美各不相同,我个人是比较喜欢效果1,不过今天也有个童鞋找我做美化,喜欢效果2。索性就把2种效果都写出来,你们喜欢哪个就用哪个。(表情会随着星期几变动。)

配置步骤

这里需要3个步骤,第一步是修改PHP,第二步是配置小工具,第三步是写CSS。

第一步,修改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
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
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("2022-03-14"))/86400);
echo "var tj_wdyx="."'$wdyx_time'";
?>
</script>

将上面的代码,放到 wp-content/themes/zibll/header.php 文件里面的底部,如下图

图片[4]-给子比主题加一个不一样的统计模块

第二步,新建小工具

后台->外观->小工具->首页-底部全宽度->新增组件,自定义HTML,把下面的代码放进去。

效果1

<div id="bphoo-info-wg-mian">
  <div class="bphoo-info-item">
    <div class="bphoo-yxsj-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-xiuxiyixia"></use>
      </svg>
      <span class="bphoo-i-num"
        ><script type="text/javascript">
          document.write(tj_wdyx);
        </script></span
      >
      <p>运行时间</p>
    </div>
    <div class="bphoo-yhzs-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-zhanghuguanli"></use>
      </svg>
      <span class="bphoo-i-num"
        ><script type="text/javascript">
          document.write(tj_jstext);
        </script></span
      >
      <p>用户总数</p>
    </div>
    <div class="bphoo-llzs-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-yanjing"></use>
      </svg>
      <span class="bphoo-i-num"
        ><script type="text/javascript">
          document.write(tj_view);
        </script></span
      >
      <p>浏览总数</p>
    </div>
    <div class="bphoo-wz-item">
      <div class="bphoo-wz-sty bphoo-wzzs-item">
        <svg class="icon fa-2x" aria-hidden="true">
          <use xlink:href="#icon-xiezuoye"></use>
        </svg>
        <span class="bphoo-i-num"
          ><script type="text/javascript">
            document.write(tj_rzzs);
          </script></span
        >
        <p>文章总数</p>
      </div>
      <div class="bphoo-wz-sty bphoo-jrfb-item">
        <svg class="icon fa-2x" aria-hidden="true">
          <use xlink:href="#icon-aixin"></use>
        </svg>
        <span class="bphoo-i-num"
          ><script type="text/javascript">
            document.write(tj_24h);
          </script></span
        >
        <p>今日发布</p>
      </div>
    </div>
    <div class="bphoo-sjcs-item">
      <div class="bphoo-sjcj-m">
        <span style="font-size: 30px">今日</span>
        <div id="bphoo-date-text"></div>
        <div id="bphoo-week-text"></div>
        <div class="bphoo-meo-item">
          <img id="bphoo-meos" src="https://img.wiiuii.cn/emo/expression-1.png" alt="emo" />
        </div>
        <div class="bphoo-sjcj-content">
          <span id="bphoo-fatalism"></span>
        </div>
      </div>
    </div>    
  <div class="bphoo-sjcs-item2"><iframe src="https://bphoo.com/taikongrenshizhong/huaweiclock.html" width="290" height="290" frameborder="no"></iframe></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 = [
    "星期日",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六"
  ];
  $("#bphoo-date-text").html(year + "年" + mon + "月" + date + "日");
  $("#bphoo-week-text").html(weeks[week]);
  if (week > 0 && week < 5) {
    $("#bphoo-fatalism").html("再坚持" + (5 - week) + "天就到周末啦!");
  } else if (week === 5) {
    $("#bphoo-fatalism").html("啊啊啊,明天就是周末啦!");
  } else {
    $("#bphoo-fatalism").html("今天是周末,好好休息一下吧!");
  }
  $("#bphoo-meos").attr(
    "src","https://img.wiiuii.cn/emo/expression-" + week + ".png"
  );
});
$("#bphoo-info-wg-mian").parents(".zib-widget").css({
  padding: "0",
  background: "none"
});
</script>

注意:有需要修改SVG图标的童鞋,把下面的 #icon-xiuxiyixia 这串代码,改成你自己的就行(一共有5个),如果不懂或者不需要改的,继续往下看。

<svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-xiuxiyixia"></use>

效果2

<div id="bphoo-info-wg-mian">
  <div class="bphoo-info-item">
    <div class="bphoo-yxsj-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-xiuxiyixia"></use>
      </svg>
      <span class="bphoo-i-num"
        ><script type="text/javascript">
          document.write(tj_wdyx);
        </script></span
      >
      <p>运行时间</p>
    </div>
    <div class="bphoo-yhzs-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-zhanghuguanli"></use>
      </svg>
      <span class="bphoo-i-num"
        ><script type="text/javascript">
          document.write(tj_jstext);
        </script></span
      >
      <p>用户总数</p>
    </div>
    <div class="bphoo-llzs-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-yanjing"></use>
      </svg>
      <span class="bphoo-i-num"
        ><script type="text/javascript">
          document.write(tj_view);
        </script></span
      >
      <p>浏览总数</p>
    </div>
    <div class="bphoo-wz-item">
      <div class="bphoo-wz-sty bphoo-wzzs-item">
        <svg class="icon fa-2x" aria-hidden="true">
          <use xlink:href="#icon-xiezuoye"></use>
        </svg>
        <span class="bphoo-i-num"
          ><script type="text/javascript">
            document.write(tj_rzzs);
          </script></span
        >
        <p>文章总数</p>
      </div>
      <div class="bphoo-wz-sty bphoo-jrfb-item">
        <svg class="icon fa-2x" aria-hidden="true">
          <use xlink:href="#icon-aixin"></use>
        </svg>
        <span class="bphoo-i-num"
          ><script type="text/javascript">
            document.write(tj_24h);
          </script></span
        >
        <p>今日发布</p>
      </div>
    </div>
    <div class="bphoo-sjcs-item">
      <div class="bphoo-sjcj-m">
        <span style="font-size: 30px">今日</span>
        <div id="bphoo-date-text"></div>
        <div id="bphoo-week-text"></div>
        <div class="bphoo-meo-item">
          <img id="bphoo-meos" src="https://img.wiiuii.cn/emo/expression-1.png" alt="emo" />
        </div>
        <div class="bphoo-sjcj-content">
          <span id="bphoo-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 = [
    "星期日",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六"
  ];
  $("#bphoo-date-text").html(year + "年" + mon + "月" + date + "日");
  $("#bphoo-week-text").html(weeks[week]);
  if (week > 0 && week < 5) {
    $("#bphoo-fatalism").html("再坚持" + (5 - week) + "天就到周末啦!");
  } else if (week === 5) {
    $("#bphoo-fatalism").html("啊啊啊,明天就是周末啦!");
  } else {
    $("#bphoo-fatalism").html("今天是周末,好好休息一下吧!");
  }
  $("#bphoo-meos").attr(
    "src","https://img.wiiuii.cn/emo/expression-" + week + ".png"
  );
});
$("#bphoo-info-wg-mian").parents(".zib-widget").css({
  padding: "0",
  background: "none"
});
</script>

注意:有需要修改SVG图标的童鞋,把下面的 #icon-xiuxiyixia 这串代码,改成你自己的就行(一共有5个),如果不懂或者不需要改的,继续往下看。

<svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-xiuxiyixia"></use>

第三步,配置CSS

效果1 CSS ,放在后台的自定义CSS样式里即可。

.bphoo-info-item{display:grid;grid-gap:15px;grid-template-columns: repeat(6,1fr);grid-template-rows:repeat(2,1fr);width:100%;height:280px;margin-bottom:15px;}
.bphoo-llzs-item, .bphoo-sjcs-item, .bphoo-yhzs-item, .bphoo-yxsj-item{width:100%;height:100%;border-radius:8px;text-align:center;box-shadow:0 2px 4px 0 rgba(0,0%,0%,5%);background-color:var(--main-bg-color);overflow:hidden;padding:5px;box-sizing:border-box;}
.bphoo-i-num{font-size:30px;font-weight:700}
.bphoo-yxsj-item{display:flex;align-items:center;justify-content:center;flex-direction:column}
.bphoo-yhzs-item{display:flex;align-items:center;justify-content:center;flex-direction:column}
.bphoo-llzs-item{display:flex;align-items:center;justify-content:center;flex-direction:column}
.bphoo-wz-item{display:grid;grid-gap:20px;grid-template-columns:repeat(2,1fr);grid-column: 3/6;grid-row:1/2;overflow:unset!important;box-shadow:none!important;padding:0!important;}
.bphoo-wz-sty{width:100%;height:100%;border-radius:8px;display:flex;align-items:center;justify-content:center;flex-direction:column;background-color:var(--main-bg-color);box-shadow:0 2px 4px 0 rgba(0,0%,0%,5%)}
.bphoo-sjcs-item{grid-row: 1/3;grid-column: 1/3;}
.bphoo-sjcj-m{position:relative;font-size:20px;font-weight:700;text-align:left;width:100%;height:100%;padding:10px;box-sizing:border-box}
.bphoo-sjcj-content{text-align:center;margin-top:10px}
.bphoo-meo-item{width:100px;height:100px;margin:0 auto}
.bphoo-meo-item>img{width:100%;height:100%;background-size:cover;background-repeat:no-repeat;background-position:center center;cursor:pointer}
svg.icon.fa-2x {margin-top: 15px;}
@media screen and (max-width:959px){.bphoo-info-item{grid-gap:10px;grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(4,1fr);height:500px;}
.bphoo-sjcs-item{grid-row:3/5;grid-column:1/4}
.bphoo-i-num{font-size:20px}
.bphoo-sjcj-m{font-size:16px}}
.enlighter-default .enlighter{max-height:400px;overflow-y:auto !important;}.posts-item .item-heading>a {font-weight: bold;color: unset;}@media (max-width:640px) {.meta-right .meta-view{display: unset !important;}}
.bphoo-sjcs-item2 {grid-row: 1/3;}
.bphoo-sjcs-item2 {width: 100%;height: 100%;border-radius: 8px;text-align: center;box-shadow: 0 2px 4px 0 rgba(0,0%,0%,5%);background-color: var(--main-bg-color);box-sizing: border-box;grid-row: 1/3;grid-column: 6/6;}
@media screen and (max-width:959px){.bphoo-wz-item{grid-column: 1/4}.bphoo-sjcs-item2 {display:none}}

效果2 CSS ,放在后台的自定义CSS样式里即可。

不会改SVG图标怎么办?

按照上面的步骤弄好就基本就搞定了,不过!我相信有不少童鞋都不懂怎么改成自己的SVG图标,或者不愿意自己改,因为的确挺麻烦的。所以,可以用我的,把下面这两串代码,放在后台->自定义底部HTML代码里面,你连修改SVG都不用了,就这么简单。

------本页内容已结束,喜欢请分享------

感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
评论 共5条
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片
    • 头像wujianhaoNB0