效果图:
两个步骤
第一步:
在子比主题的主题目录下,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("2022-08-09"))/86400);
echo "var tj_wdyx="."'$wdyx_time'";
?>
</script>
<!--调用信息代码结束-->
第二步:
在后台––外观—小工具—网站选择的是(所有页面-底部全宽度)
自定义HTML,把下面代码放进去,即可在预览页面看到效果
<!--信息统计开始-->
<div id="nuandao" style="box-shadow: 0 0 10px var(--main-shadow);">
<div class="siteCount">
<div class="wrapper">
<div class="p-wh">
<ul>
<li>
<p><img src="https://yizhi2024.top/wp-content/uploads/2024/07/我的VIP.svg" alt="会员总数图标" class="icon" style="width: 31px; height: 31px;"></p>
<span><script type="text/javascript">
document.write(tj_jstext);
</script></span>
<p>会员总数</p>
</li>
<li>
<p><img src="https://yizhi2024.top/wp-content/uploads/2024/07/我的VIP.svg" alt="文章总数图标" class="icon" style="width: 31px; height: 31px;"></p>
<span><script type="text/javascript">
document.write(tj_rzzs);
</script></span>
<p>文章总数</p>
</li>
<li>
<p><img src="https://yizhi2024.top/wp-content/uploads/2024/07/我的VIP.svg" alt="浏览总数图标" class="icon" style="width: 31px; height: 31px;"></p>
<span id="view-count"></span>
<p>浏览总数</p>
</li>
<li>
<p><img src="https://yizhi2024.top/wp-content/uploads/2024/07/我的VIP.svg" alt="今日发布图标" class="icon" style="width: 31px; height: 31px;"></p>
<span><script type="text/javascript">
document.write(tj_24h);
</script></span>
<p>今日发布</p>
</li>
<li>
<p><img src="https://yizhi2024.top/wp-content/uploads/2024/07/我的VIP.svg" alt="稳定运行图标" class="icon" style="width: 31px; height: 31px;"></p>
<span><script type="text/javascript">
document.write(tj_wdyx);
</script></span>
<p>稳定运行</p>
</li>
</ul>
</div>
<div class="join">
<p style="text-align:center"><a href="https://yizhi2024.top/user/vip"><font color="white">成为网站会员,快速获取大量优质资源!</font></a><br></p>
</div>
</div>
</div>
</div>
<style type="text/css">
/*背景图*/#nuandao .siteCount{position: relative; padding: 60px 0; background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),url(https://yizhi2024.top/wp-content/uploads/2024/07/背景.jpg) center center / cover no-repeat fixed;/*border-radius:8px;*/border-radius: var(--main-radius);}#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;}@media screen and (max-width: 768px){#nuandao .siteCount ul li span{font-size: 20px; font-family: Arial;}}#nuandao .p-wh{font-weight:700;}
/*底部文本p标签*/.join{padding-top: 20px;font-size: 15px;color: #FFF;letter-spacing: 0.5px;font-weight: 600;}
@media screen and (max-width: 768px){#nuandao .siteCount{position: relative; padding: 30px 0;border-radius:8px;}#nuandao .siteCount .cover{height: 100%; width: 100%; background: rgba(0, 0, 0, 0.3); position: absolute; top: 0; left: 0;}}
</style>
<script>
//document.getElementById("nuandao").parentNode.parentNode.style.backgroundColor="transparent"
document.getElementById("nuandao").parentNode.parentNode.style.padding=0
// Convert view count to "W" if over 10,000
var viewCount = parseInt(tj_view, 10);
if (viewCount >= 10000) {
viewCount = (viewCount / 10000).toFixed(1) + 'W';
}
document.getElementById("view-count").innerText = viewCount;
</script>
<!--信息统计结束-->
如何修改成自己的东西:
在第一步:
时间代码:2022-08-09,这个是时间,改成自己的时间
在第二步的:
1、https://yizhi2024.top/wp-content/uploads/2024/07/我的VIP.svg,改成你自己的图标链接地址
2、31px可以修改成自己网站适合的大小
3、背景图的修改:https://yizhi2024.top/wp-content/uploads/2024/07/背景.jpg把这个链接改成自己背景图的修改
我的这个有什么优化:
1、我的这个不是引用图标,是使用图标地址,这样的话,只要我的网站存在,我的图标就永远存在
2、浏览总数改用W来显示,这样更直观
3、背景图的padding,可以修改整体的高度
© 版权声明
THE END
相关推荐