网站底部添加横向网站信息统计模块,自动获取日期及访问者IP

文章具有时效性。下载《英灵神殿》汉化模组时,请确保模组版本与当前游戏版本兼容。

如需更新或查找您所需的汉化模组,请点击此处提交

安装教程:

  • 为了网站优化因此不直接放在子比主题自定义 css 中,而是文件样式引用,总共分为三步,源码也在文章底部,图标也已经集成无需二次修改

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>


<!--统计信息函数横向优化版-->

2、在后台–外观–小工具–首页底部全宽度 添加以下代码

  • 此处记得查看代码中我注释的位置,修改相应的文件路径,或者直接搜索:域名替换成你自己的,查看修改
    <script src="//at.alicdn.com/t/font_2820512_foowmlcjyf.js"></script>
    <link rel="stylesheet" type="text/css" href="https://域名/statistics/tj2.css">
    <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"
              ><script src="https://域名/statistics/ip.php"></script><script type="text/javascript">
        document.write(returnCitySN["cip"])
        </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="https://域名/statistics/week/login.png" alt="emo" />
            </div>
            <div class="mizhi-sjcj-content">
              <span id="mizhi-fatalism"></span>
            </div>
          </div>
        </div>    
      <div class="mizhi-sjcs-item2"><iframe src="https://域名/statistics/tkr/" 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 = [
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六"
      ];
      $("#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","https://域名/statistics/week-" + week + ".webp"
      );
    });
    $("#mizhi-info-wg-mian").parents(".zib-widget").css({
      padding: "0",
      background: "none"
    });
    </script></div>

    3、下载下面我提供的源码文件直接上传到服务器,具体位置可自行决定,最后记得修改第二步骤中代码引用的位置即可

  •  
    123云盘

    提取码

 预览效果

网站底部添加横向网站信息统计模块,自动获取日期及访问者IP-资源工坊-游戏模组资源分享

本站提供服务器出租☞💻多人联机.服务器24小时运行.小白开服无忧💻
© 版权声明
THE END
喜欢就支持一下吧
点赞70赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容