18.1 添加核心函数
子比主题的主题目录下,在路径/wordpress/wp-content/themes/zibll/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.itzhiyin.cn
*/
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.itzhiyin.cn
*/
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-10-20"))/86400);
echo "var tj_wdyx="."'$wdyx_time'";
?>
</script>
<!--统计信息函数横向优化版-->
18.2 统计样式代码下载
通过文末的网盘链接直接存储在自己云盘或者下载使用【有提取码的记得先复制提取码再点击下载哟】
解压密码:微信扫码或搜索公众号”星河泪“,关注后回复”解压密码“即可获取解压密码。
下载后将文件上传到子比主题目录或者其他地方,18.3中的路径即为此文件位置
18.3 添加底部全宽度代码
在后台–外观–小工具–首页底部全宽度 添加以下自定义HTML代码:
这里的"https://xylh.top/wp-content/themes/zibll/dbtj/"路径需要修改为自己的统计样式代码存放位置
<script src="//at.alicdn.com/t/font_2820512_foowmlcjyf.js"></script>
<link rel="stylesheet" type="text/css" href="https://xylh.top/wp-content/themes/zibll/dbtj/tj2.css"><!--需修改文件位置 1-->
<div class="textwidget custom-html-widget"><div id="itzhiyin-info-wg-mian">
<div class="itzhiyin-info-item">
<div class="itzhiyin-yxsj-item">
<svg class="icon fa-2x" aria-hidden="true">
<use xlink:href="#icon-009-shijianguanli"></use>
</svg>
<span class="itzhiyin-i-num"
><script type="text/javascript">
document.write(tj_wdyx);
</script></span>
<p>运行时间</p>
</div>
<div class="itzhiyin-yhzs-item">
<svg class="icon fa-2x" aria-hidden="true">
<use xlink:href="#icon-yonghu"></use>
</svg>
<span class="itzhiyin-i-num"
><script type="text/javascript">
document.write(tj_jstext);
</script></span>
<p>用户总数</p>
</div>
<div class="itzhiyin-llzs-item">
<svg class="icon fa-2x" aria-hidden="true">
<use xlink:href="#icon-liulan-5"></use>
</svg>
<span class="itzhiyin-i-num"
><script type="text/javascript">
document.write(tj_view);
</script></span
>
<p>浏览总数</p>
</div>
<div class="itzhiyin-wz-item">
<div class="itzhiyin-wz-sty itzhiyin-wzzs-item">
<svg class="icon fa-2x" aria-hidden="true">
<use xlink:href="#icon-wenzhang"></use>
</svg>
<span class="itzhiyin-i-num"
><script type="text/javascript">
document.write(tj_rzzs);
</script></span
>
<p>文章总数</p>
</div>
<div class="itzhiyin-wz-sty itzhiyin-jrfb-item">
<svg class="icon fa-2x" aria-hidden="true">
<use xlink:href="#icon-dizhi"></use>
</svg>
<span class="itzhiyin-i-num"
><script type="application/javascript">
function getIP(json) {
document.write("", json.ip);
}
</script>
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>
</span
>
<p>您的 IP 地址是</p>
</div>
</div>
<div class="itzhiyin-sjcs-item">
<div class="itzhiyin-sjcj-m">
<div style="text-align:center;">
<span style="font-size:30px">今天是 </span>
</div>
<div style="text-align:center;" id="itzhiyin-date-text"></div>
<div id="itzhiyin-week-text"></div>
<div class="itzhiyin-meo-item">
<img id="itzhiyin-meos" src="https://xylh.top/wp-content/themes/zibll/dbtj/week/login.png" alt="emo" /><!--需修改文件位置 2-->
</div>
<div class="itzhiyin-sjcj-content">
<span id="itzhiyin-fatalism"></span>
</div>
</div>
</div>
<div class="itzhiyin-sjcs-item2"><iframe src="https://xylh.top/wp-content/themes/zibll/dbtj/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 = [
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六"
];
$("#itzhiyin-date-text").html(year + "年" + mon + "月" + date + "日"+ weeks[week]);
if (week > 0 && week < 5) {
$("#itzhiyin-fatalism").html("再坚持一下还有" + (5 - week) + "天就到周末啦!");
} else if (week === 5) {
$("#itzhiyin-fatalism").html("啊啊啊,明天就是周末啦!");
} else {
$("#itzhiyin-fatalism").html("今天是周末,好好休息一下吧!");
}
$("#itzhiyin-meos").attr(
"src","https://xylh.top/wp-content/themes/zibll/dbtj/week/week-" + week + ".webp"/*需修改文件位置 4*/
);
});
$("#itzhiyin-info-wg-mian").parents(".zib-widget").css({
padding: "0",
background: "none"
});
</script></div>
18.4 效果界面展示
© 版权声明
THE END