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获取今日发布文章数量
*zje.cc
*/
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("2023-06-01"))/86400);
echo "var tj_wdyx="."'$wdyx_time'";
?>
</script>
注:函数运行日期2020-3-28改为你自己网站运行的日期。
2.在子比主题,页面&显示 - 底部页脚 - 版块一设置- 版块内部 中填入如下代码
<!-- 信息统计开始 -->
<div id="nuandao">
<div class="siteCount">
<div class="wrapper">
<ul>
<li>
<b>用户总数</b>
<span>
<script type="text/javascript">
document.write(tj_jstext);
</script>
</span>
</li>
<li>
<b>文章总数</b>
<span>
<script type="text/javascript">
document.write(tj_rzzs);
</script>
</span>
</li>
<li>
<b>浏览总数</b>
<span>
<script type="text/javascript">
document.write(tj_view);
</script>
</span>
</li>
<li>
<b>今日发布</b>
<span></span>
<span>
<script type="text/javascript">
document.write(tj_24h);
</script>
</span>
</li>
<li>
<b>稳定运行</b>
<span>
<script type="text/javascript">
document.write(tj_wdyx);
</script>
</span>
</li>
</ul>
</div>
</div>
</div>
<style type="text/css">
/* 添加以下 CSS 样式 */
#nuandao .siteCount ul li span {
color: #FF69B4;
}
</style>
<!-- 信息统计结束 -->
3.效果如下
4.如仅在首先显示,不占空间,可加入侧边栏(外观 - 小工具-自定义HTML 添加到首页 侧边栏)代码同上,效果如下
评论 (0)