子比主题-添加信息统计(用户总数,文章总数,浏览总数等)小工具
预览图
- 注:主题更新会覆盖已修改的文件,记得备份,或者关注本站!
教程
1.首登陆你的wp后台,找到外观 自定义
2.打开小工具
3.找到自己想放的位置(我是放在首页-主内容下面)
4.点击添加小工具,搜索HTML 找到自定义html
5.然后将下面的代码放入。
<div class="widget_text zib-widget widget_custom_html"><div class="textwidget custom-html-widget"><!--信息统计开始-->
<div id="nuandao">
<div class="siteCount">
<div class="wrapper">
<ul>
<li>
<b><svg class="icon fa-2x" aria-hidden="true"><use xlink:href="#iconyonghu"></use></svg></b>
<span>
<script type="text/javascript" >
document.write(jstext);
</script>
</span>
<b>用户总数</b>
</li>
<li>
<b><svg class="icon fa-2x" aria-hidden="true"><use xlink:href="#iconwenzhang"></use></svg></b>
<span><script type="text/javascript" >
document.write(tj_rzzs);
</script></span>
<b>文章总数</b>
</li>
<li>
<b><svg class="icon fa-2x" aria-hidden="true"><use xlink:href="#iconliulanjilu"></use></svg></b>
<span><script type="text/javascript" >
document.write(tj_view);
</script></span>
<b>浏览总数</b>
</li>
<li>
<b><svg class="icon fa-2x" aria-hidden="true"><use xlink:href="#iconfabu"></use></svg></b>
<span></span>
<span>
<script type="text/javascript" >
document.write(tj_24h);
</script>
</span>
<b>今日发布</b>
</li>
<li>
<b><svg class="icon fa-2x" aria-hidden="true"><use xlink:href="#iconyunhangzhengchang"></use></svg></b>
<span><script type="text/javascript" >
document.write(tj_wdyx);
</script></span>
<b>稳定运行</b>
</li>
</ul>
<div class="join-vip">
<p style="text-align:center">欢迎光临老奶狗博客,快速获取优质IT资源吧!<br> By:NaiGou</p>
</div>
</div>
</div>
</div>
<style type="text/css">
/*背景图*/#nuandao .siteCount{position: relative; padding: 60px 0; background: url(https://www.owoc.cn/img/bg.jpg) center center / cover no-repeat fixed;border-radius:5px;}#nuandao .siteCount .cover{height: 100%; width: 100%; background: rgba(0, 0, 0, 0.3); position: absolute; top: 0; left: 0;}/*内容*/#nuandao .siteCount .wrapper{position: relative; z-index: 10; width: 100%; max-width: 100%; margin: 0 auto;}#nuandao .siteCount ul{display: flex;}#nuandao .siteCount ul li{width: 20%; color: #fff; text-align: center;}/*模块*/#nuandao .siteCount ul li span{font-size: 48px; font-family: Arial;}#nuandao .siteCount ul li b{display: block; font-weight: normal; font-size: 14px;}@media screen and (max-width: 768px){#nuandao .siteCount ul li span{font-size: 20px; font-family: Arial;}}.home_row{position: relative; border-bottom: 1px dashed rgba(255, 255, 255, 0.5);}/*底部文本p标签*/#nuandao .siteCount .join-vip p{margin-top: 15px;font-size: 15px;color: #FFF;letter-spacing: 0.5px;font-family: Arial;}
</style>
<script>
document.getElementById("nuandao").parentNode.parentNode.style.backgroundColor="transparent"
</script>
<!--信息统计结束--></div></div>
6.点击完成,然后点击发布。
7.打开你的服务器,找到 你的域名根目录/wp-content/themes/header.php文件并打开。
8.将下面代码放到所有代码最下方。
<!--统计信息函数-->
<script type="text/javascript" >
<?php
//用户总数
$users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");echo "var jstext="."'$users'";
?>
</script>
<script type="text/javascript" >
<?php
/*
* WordPress获取今日发布文章数量
*www.wiiuii.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.wiiuii.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("2018-12-9"))/86400);
echo "var tj_wdyx="."'$wdyx_time'";
?>
</script>
9.保存,并强制刷新你的网页,即可。
感谢您的来访,获取更多精彩文章请收藏本站。

THE END