子比主题美化-网站底部信息统计模块自动获取日期及访问者IP

子比主题美化-网站底部信息统计模块自动获取日期及访问者IP-大海资源库
子比主题美化-网站底部信息统计模块自动获取日期及访问者IP
此内容为免费资源,请登录后查看
0积分
资源来源于网络,侵权立删
站长微信:Da_muzi
免费资源
已售 20

直接上教程:

  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 获取今日发布文章数量
 */
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 整站文章访问计数
 */
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("2021-6-21"))/86400);
echo "var tj_wdyx="."'$wdyx_time'";
?>
</script>
<!--统计信息函数-->

注意:54行:(2021-6-21) 改成自己的建站日期!!

2. footer.php添加以下面代码:

<!--网站统计-->
<script src="//at.alicdn.com/t/font_2820512_foowmlcjyf.js"></script>
<link rel="stylesheet" type="text/css" href="/tongji/tj2.css"><!--需修改文件位置 1-->
<div class="textwidget custom-html-widget"><div id="mizhi-info-wg-mian">
  <div class="mizhi-info-item">
  
    <div class="mizhi-yxsj-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-009-shijianguanli"></use>
      </svg>
      <span class="mizhi-i-num"
        ><script type="text/javascript">
          document.write(tj_wdyx);
        </script></span>
      <p>运行时间</p>
    </div>
    
    <div class="mizhi-yhzs-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-yonghu"></use>
      </svg>
      <span class="mizhi-i-num"
        ><script type="text/javascript">
          document.write(tj_jstext);
        </script></span>
      <p>用户总数</p>
    </div>
    
    <div class="mizhi-llzs-item">
      <svg class="icon fa-2x" aria-hidden="true">
        <use xlink:href="#icon-liulan-5"></use>
      </svg>
      <span class="mizhi-i-num"
        ><script type="text/javascript">
          document.write(tj_view);
        </script></span>
      <p>浏览总数</p>
    </div>
    
    <div class="mizhi-wz-item">
      <div class="mizhi-wz-sty mizhi-wzzs-item">
        <svg class="icon fa-2x" aria-hidden="true">
          <use xlink:href="#icon-wenzhang"></use>
        </svg>
        <span class="mizhi-i-num"
          ><script type="text/javascript">
            document.write(tj_rzzs);
          </script></span>
        <p>文章总数</p>
      </div>
      
     <div class="mizhi-wz-sty mizhi-jrfb-item">
        <svg class="icon fa-2x" aria-hidden="true">
          <use xlink:href="#icon-dizhi"></use>
        </svg>
        <span class="mizhi-i-num" id="mizhi-i-num"
          ><script>var ip = 'https://www.aiik.cn/api/ip.php';$.getJSON(ip,function(data){$('#mizhi-i-num').html(data.ip);})</script></span>
        <p>您的 IP 地址是</p>
      </div>
    </div>
    
    <div class="mizhi-sjcs-item">
      <div class="mizhi-sjcj-m">
        <span style="font-size: 30px">今天是</span>
        <div id="mizhi-date-text"></div>
        <div id="mizhi-week-text"></div>
        <div class="mizhi-meo-item">
          <img id="mizhi-meos" src="/tongji/week/login.png" alt="emo" /><!--需修改文件位置 2-->
        </div>
        <div class="mizhi-sjcj-content">
          <span id="mizhi-fatalism"></span>
        </div>
      </div>
    </div>    
  <div class="mizhi-sjcs-item2"><iframe src="/tongji/tkr/" width="290" height="290" frameborder="no"></iframe></div><!--需修改文件位置 3-->
  </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 = [
    "星期日",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六"
  ];
  $("#mizhi-date-text").html(year + "年" + mon + "月" + date + "日"+ weeks[week]);

  if (week > 0 && week < 5) {
    $("#mizhi-fatalism").html("再坚持一下还有" + (5 - week) + "天就到周末啦!");
  } else if (week === 5) {
    $("#mizhi-fatalism").html("啊啊啊,明天就是周末啦!");
  } else {
    $("#mizhi-fatalism").html("今天是周末,好好休息一下吧!");
  }
  $("#mizhi-meos").attr(
    "src","/tongji/week/week-" + week + ".webp"/*需修改文件位置 4*/
  );
});
$("#mizhi-info-wg-mian").parents(".zib-widget").css({
  padding: "0",
  background: "none"
});
</script></div>

3. 最后下载重要css文件上传到网站根目录方可生效。

有问题及时联系站长,QQ:1240555208
更多优质资源在QQ群里,可以进群领取:467392290~
© 版权声明
THE END
点赞15 分享
及时反馈~ 抢沙发

请登录后发表评论

    暂无评论内容