子比主题添加底部统计信息模块小工具

前言

子比主题添加底部统计信息模块小工具

今天从网上找来,自己刚弄的,感觉还可以,就分享一波!主要统计信息有用户数、文章数、浏览数、今日发布、运行时间这几个功能。嗯…不知道怎么肥事,唯一美中不足的是手机端的按钮那里总是靠左那么一点点,我也不知道该改哪里,如果哪位大佬知道的话,请在下方留言告知我修改一下,Thanks♪(・ω・)ノ

统计信息模块小工具主要采用前端HTML+CSS和后端函数,通过后端提供功能函数,然后前台获取到后台提供的数据来显示信息功能。有兴趣的大佬可以修改一下。

本站主要采用WordPress+子比主题,没有测试过其他主题,如果你用的其他主题可以自己测试一下,嘻嘻!本站主要以子比主题来写。

下面就分享教程及代码:

食用教程

1.在子比主题的主题目录下,header.php底部添加以下函数代码:
<strong><</strong>!--统计信息函数--<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong><strong><</strong>?php//用户总数$users = $wpdb-<strong>></strong>get_var<strong>(</strong>"SELECT COUNT(ID) FROM $wpdb->users"<strong>)</strong>;echo "var jstext="."'$users'";?<strong>></strong><strong><</strong>/script<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong><strong><</strong>?php/* * WordPress获取今日发布文章数量 *www.wiiuii.cn */function nd_get_24h_post_count<strong>(){</strong>  $today = getdate<strong>()</strong>;  $query = new WP_Query<strong>(</strong> 'year=' . $today<strong>[</strong>"year"<strong>]</strong> . '&monthnum=' . $today<strong>[</strong>"mon"<strong>]</strong> . '&day=' . $today<strong>[</strong>"mday"<strong>])</strong>;  $postsNumber = $query-<strong>></strong>found_posts;  return $postsNumber;<strong>}</strong>$post_24h = nd_get_24h_post_count<strong>()</strong>;echo "var tj_24h="."'$post_24h'";?<strong>></strong><strong><</strong>/script<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong><strong><</strong>?php/* * WordPress整站文章访问计数 *www.wiiuii.cn */function nd_get_all_view<strong>(){</strong>  global $wpdb;  $count=0;  $views= $wpdb-<strong>></strong>get_results<strong>(</strong>"SELECT * FROM $wpdb->postmeta WHERE meta_key='views'"<strong>)</strong>;  foreach<strong>(</strong>$views as $key=<strong>></strong>$value<strong>){</strong>    $meta_value=$value-<strong>></strong>meta_value;    if<strong>(</strong>$meta_value!=' '<strong>){</strong>      $count+=<strong>(</strong>int<strong>)</strong>$meta_value;    <strong>}</strong>  <strong>}</strong>return $count;<strong>}</strong>$post_view = nd_get_all_view<strong>()</strong>;echo "var tj_view="."'$post_view'";?<strong>></strong><strong><</strong>/script<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong><strong><</strong>?php//日志总数$count_posts = wp_count_posts<strong>()</strong>; $published_posts =$count_posts-<strong>></strong>publish;echo "var tj_rzzs="."'$published_posts'";?<strong>></strong><strong><</strong>/script<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong><strong><</strong>?php//稳定运行$wdyx_time = floor<strong>((</strong>time<strong>()</strong>-strtotime<strong>(</strong>"2020-3-28"<strong>))</strong>/86400<strong>)</strong>;echo "var tj_wdyx="."'$wdyx_time'";?<strong>></strong><strong><</strong>/script<strong>></strong>

注:函数运行日期2020-3-28改为你自己网站运行的日期。

2.在后台–>外观–>小工具–>自定义HTML,把自定义HTML放到合适的版块里(子比主题放在首页-底部全宽度),然后把下面代码复制粘贴进去,即可在前台显示。
<!--信息统计开始--><strong><</strong>div id="nuandao"<strong>></strong>    <strong><</strong>div class="siteCount"<strong>></strong>      <strong><</strong>div class="wrapper"<strong>></strong>        <strong><</strong>ul<strong>></strong>          <strong><</strong>li<strong>></strong>            <strong><</strong>span<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong>document.write(jstext);<strong></</strong>script<strong>></strong><strong></</strong>span<strong>></strong>            <strong><</strong>b<strong>></strong>用户总数<strong></</strong>b<strong>></strong>          <strong></</strong>li<strong>></strong>          <strong><</strong>li<strong>></strong>            <strong><</strong>span<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong>document.write(tj_rzzs);<strong></</strong>script<strong>></strong><strong></</strong>span<strong>></strong>            <strong><</strong>b<strong>></strong>文章总数<strong></</strong>b<strong>></strong>          <strong></</strong>li<strong>></strong>          <strong><</strong>li<strong>></strong>            <strong><</strong>span<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong>document.write(tj_view);<strong></</strong>script<strong>></strong><strong></</strong>span<strong>></strong>            <strong><</strong>b<strong>></strong>浏览总数<strong></</strong>b<strong>></strong>          <strong></</strong>li<strong>></strong>          <strong><</strong>li<strong>></strong>            <strong><</strong>span<strong>></strong><strong></</strong>span<strong>></strong>            <strong><</strong>span<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong>document.write(tj_24h);<strong></</strong>script<strong>></strong><strong></</strong>span<strong>></strong>            <strong><</strong>b<strong>></strong>今日发布<strong></</strong>b<strong>></strong>          <strong></</strong>li<strong>></strong>          <strong><</strong>li<strong>></strong>            <strong><</strong>span<strong>></strong><strong><</strong>script type="text/javascript" <strong>></strong>document.write(tj_wdyx);<strong></</strong>script<strong>></strong><strong></</strong>span<strong>></strong>            <strong><</strong>b<strong>></strong>稳定运行<strong></</strong>b<strong>></strong>          <strong></</strong>li<strong>></strong>        <strong></</strong>ul<strong>></strong>        <strong><</strong>div class="join-vip"<strong>></strong>          <strong><</strong>a  href="/" target="_blank" style="background-image: linear-gradient(to right, #D279EE, #F8C390); text-align:center;" <strong>></strong>立即加入<strong></</strong>a<strong>></strong>         <strong><</strong>p<strong>></strong>加入星语的小木屋,快速获取优质IT资源!<strong></</strong>p<strong>></strong>        <strong></</strong>div<strong>></strong>      <strong></</strong>div<strong>></strong>    <strong></</strong>div<strong>></strong>  <strong></</strong>div<strong>></strong><strong><</strong>style type="text/css"<strong>></strong> body{padding: 0px; margin: 0px;} *, *::before, *::after{box-sizing: border-box;} ol, ul{list-style: none;} a{color: inherit; text-decoration: none; vertical-align: top;}/*背景图*/#nuandao .siteCount{position: relative; padding: 60px 0; background: url(https://img.wiiuii.cn/tutu/007.jpg) center center / cover no-repeat fixed;}#nuandao .siteCount .cover{height: 100%; width: 100%; background: rgba(0, 0, 0, 0.6); position: absolute; top: 0; left: 0;}/*内容*/#nuandao .siteCount .wrapper{position: relative; z-index: 10; width: 1400px; 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;}/*按钮*/#nuandao .siteCount .join-vip{text-align: center; color: #fff; margin-top: 30px;}#nuandao .siteCount .join-vip a{display: inline-block; border: 0; border-radius: 5px; transition: all 0.3s; padding: 10px 30px; font-size: 15px; letter-spacing: 0.5px; background-color: var(--primary-color); background-image: -webkit-gradient( linear, left top, right top, from(#006eff), to(#13adff) ); background-image: -webkit-linear-gradient(left, #006eff, #13adff); background-image: -o-linear-gradient(left, #006eff 0, #13adff 100%); background-image: linear-gradient(90deg, #006eff, #13adff); -webkit-box-shadow: 0 5px 10px 0 rgba(16, 110, 253, 0.3); box-shadow: 0 5px 10px 0 rgba(16, 110, 253, 0.3); color: #fff;}#nuandao .siteCount .join-vip p{margin-top: 15px; font-size: 14px; color: rgba(255, 255, 255, 0.8); letter-spacing: 0.5px; font-family: Arial;}@media screen and (max-width: 768px){#nuandao .siteCount ul li span{font-size: 20px; font-family: Arial;}} <strong></</strong>style<strong>></strong><strong><</strong>script<strong>></strong>document.getElementById("nuandao").parentNode.parentNode.style.backgroundColor="transparent"<strong></</strong>script<strong>></strong><!--信息统计结束-->

注:背景图自己修改,不会的评论留言。

截图

手机端:

手机端-子比主题添加底部统计信息模块小工具

电脑端:

电脑端-子比主题添加底部统计信息模块小工
© 版权声明
THE END
喜欢就支持一下吧
点赞1赞赏
分享
评论 抢沙发