![图片[1]-【网站美化】底部横向网站信息统计模块-凤翼天翔剧社](https://www.bona99.com/wp-content/uploads/2025/02/66195cbf8793b-e1738834218390-1024x223.png)
子比主题的主题目录下,header.php
底部添加下方核心函数代码
<script type="text/javascript" >
//文章总数
<?php $count_posts = wp_count_posts(); $published_posts =$count_posts->publish;echo "var tj_wzzs="."'$published_posts'";?>
//本周发布
<?php $post_wpdb = get_posts_count_from_last_168h($post_type ='post');echo "var tj_bzfb="."'$post_wpdb'";?>
//运行时间
<?php $wdyx_time = floor((time()-strtotime("2024-6-25 0:0:0"))/86400);echo "var tj_yxsj="."'$wdyx_time'";?>
//用户总数
<?php global $wpdb;$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");echo "var tj_yhzs="."'$users'";?>
//总访问量
<?php $post_view = nd_get_all_view();echo "var tj_yhzl="."'$post_view'";?>
</script>
路径:主题根目录zibll/functions.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;
}
/* 统计本周文章数量 */
function get_posts_count_from_last_168h($post_type ='post') {
global $wpdb;
$numposts = $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(ID) ".
"FROM {$wpdb->posts} ".
"WHERE ".
"post_status='publish' ".
"AND post_type= %s ".
"AND post_date> %s",
$post_type, date('Y-m-d H:i:s', strtotime('-168 hours'))
)
);
return $numposts;
}
WordPress后台
>> 外观
>> 小工具
>> 首页底部全宽度自定义HTML
添加以下代码
<div class="textwidget custom-html-widget"><div id="mizhi-info-wg-mian">
<div class="mizhi-info-item">
<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" rel="external nofollow" ></use>
</svg>
<span class="mizhi-i-num"><script type="text/javascript">
document.write(tj_wzzs);
</script>篇</span>
<span class="frame-bg" title="文章数目">文章数目</span>
</div>
<div class="mizhi-wz-sty mizhi-jrfb-item">
<svg class="icon fa-2x" aria-hidden="true">
<use xlink:href="#icon-meizhouyilian" rel="external nofollow" ></use>
</svg>
<span class="mizhi-i-num"><script type="text/javascript">
document.write(tj_bzfb);
</script>篇</span>
<span class="frame-bg" title="本周发布">本周发布</span>
</div>
</div>
<div class="mizhi-yhzs-item">
<svg class="icon fa-2x" aria-hidden="true">
<use xlink:href="#icon-huangguanyonghu" rel="external nofollow" ></use>
</svg>
<span class="mizhi-i-num"><script type="text/javascript">
document.write(tj_yhzs);
</script>位</span>
<span class="frame-bg" title="注册用户">注册用户</span>
</div>
<div class="mizhi-yxsj-item">
<svg class="icon fa-2x" aria-hidden="true">
<use xlink:href="#icon-zuji" rel="external nofollow" ></use>
</svg>
<span class="mizhi-i-num"><script type="text/javascript">
document.write(tj_yxsj);
</script>天</span>
<span class="frame-bg" title="运行时间">运行时间</span>
</div>
<div class="mizhi-llzs-item">
<svg class="icon fa-2x" aria-hidden="true">
<use xlink:href="#icon-liulan" rel="external nofollow" ></use>
</svg>
<span class="mizhi-i-num "><script type="text/javascript">
document.write(tj_yhzl);
</script>次</span>
<span class="frame-bg" title="浏览次数">浏览次数</span>
</div>
<div class="mizhi-sjcs-item">
<div class="mizhi-sjcj-m">
<span class="mizhi-i-num">今天是</span>
<div id="mizhi-date-text"></div>
<div id="mizhi-week-text"></div>
<div class="mizhi-meo-item">
<img id="mizhi-meos" src="https://blog.zbiwl.com/demo/sz/week-1.webp" alt="emo">
</div>
<div class="mizhi-sjcj-content">
<span id="mizhi-fatalism"></span>
</div>
</div>
</div>
<div class="mizhi-sjcs-item2"><iframe src="https://blog.zbiwl.com/demo/sz/" width="290" height="280" 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://blog.zbiwl.com/demo/sz/week-" + week + ".webp"
);
});
$("#mizhi-info-wg-mian").parents(".zib-widget").css({
padding: "0",
background: "none"
});
</script></div>
<link rel="stylesheet" href="https://blog.zbiwl.com/demo/sz/tj2.css" type="text/css">
一定要引入图标链接,我这里引入的是阿里的icon的图标,放到自定义底部HTML代码,自己可自行更换,链接如下
<script src="https://www.bona99.com/wp-content/uploads/2025/02/font_4054251_lyuxfz4jkfj.js"></script>
最后,Zibll主题设置 >> 全局&功能 >> 自定义代码 >> 自定义CSS样式
.huliku-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;}
.huliku-llzs-item, .huliku-sjcs-item, .huliku-yhzs-item, .huliku-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;}
.huliku-i-num{font-size:20px;font-weight:600}
.huliku-yxsj-item{display:flex;align-items:center;justify-content:center;flex-direction:column}
.huliku-yhzs-item{display:flex;align-items:center;justify-content:center;flex-direction:column}
.huliku-llzs-item{display:flex;align-items:center;justify-content:center;flex-direction:column}
.huliku-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;}
.huliku-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%)}
.huliku-sjcs-item{grid-row: 1/3;grid-column: 1/3;}
.huliku-sjcj-m{position:relative;font-size:20px;font-weight:700;text-align:center;width:100%;height:100%;padding:10px;box-sizing:border-box;}
.huliku-sjcj-content{text-align:center;margin-top:10px}
.huliku-meo-item{width:282px;height:120px;margin:0 auto}
.huliku-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){.huliku-info-item{grid-gap:10px;grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(4,1fr);height:500px;}
.huliku-sjcs-item{grid-row:3/5;grid-column:1/4}
.huliku-i-num{font-size:20px}
.huliku-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;}}
.huliku-sjcs-item2 {grid-row: 1/3;}
.huliku-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){.huliku-wz-item{grid-column: 1/4}.huliku-sjcs-item2 {display:none}}
.huliku-ip-item, .huliku-sjcs-item, .huliku-yhzs-item, .huliku-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;}
.huliku-ip-item{display:flex;align-items:center;justify-content:center;flex-direction:column}
温馨提示:
本文最后更新于
2025-02-06 17:33:21
,某些文章具有时效性,若有错误或已失效,请在下方
留言。
本站内容仅供学习和研究使用,请在下载后24小时内删除 凤翼天翔
Like a child, always believe in hope, I believe the dream.
像孩子一样,永远相信希望,相信梦想
THE END
暂无评论内容