当前位置:首页>WordPress>wordpress_7b2统计模块美化代码

wordpress_7b2统计模块美化代码

统计阅读总数,运行天数,文章总数,今日发布,本周发布,本站用了这几个统计

还可以用页面总数,评论总数,链接总数,分类总数

演示图:

教程

在主题的functions.php,加入以下代码

/*网站统计代码*/
function get_posts_count_from_last_24h($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('-24 hours'))
)
);
return $numposts;
}
//WordPress全部文章总浏览数
function okmg_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_week_post_count(){
    $date_query = array(
    array(
    'after'=>'1 week ago'
    )
    );$args = array(
    'post_type' => 'post',
    'post_status'=>'publish',
    'date_query' => $date_query,
    'no_found_rows' => true,
    'suppress_filters' => true,
    'fields'=>'ids',
    'posts_per_page'=>-1
    );
    $query = new WP_Query( $args );
    echo $query->post_count;
    }
    // 每日更新的文章数量
    function WeeklyUpdate() {
    $today = getdate();
    $query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"]);
    $postsNumber = $query->found_posts;
    echo $postsNumber;
    }
//用户数量代码查询
function output_user_count() { 
     $usercountdata = count_users();
     $alluser = $usercountdata['total_users']; 
     return $alluser; 
 } 
 add_shortcode('allusercount', 'output_user_count');

我是一下加入这些

后台模块添加自定义

<div class="jitheme_slide_tjmk">
            <div class="jitheme_slide_tj">
                <!--访问总数-->
                <li>
                    <i class="jitheme ji-k-line">
                    </i>
                    阅读总数:<span><?php echo okmg_all_view(); ?></span>                </li>
                <!--文章总数-->
                <li>
                    <i class="jitheme ji-k-line">
                    </i>
                    文章总数:<span><?php echo $publish_posts = wp_count_posts()->publish;?></span>                </li>
                <!--今日发布-->
                <!-- <li><i class="iconfont -->
                <!--"></i>-->
                <!--:-->
                <!--</li>-->
                <li>
                    <i class="jitheme ji-k-line">
                    </i>
                    今日发布:<span><?php WeeklyUpdate();?></span>                </li>
                <!--本周发布-->
                <li>
                    <i class="jitheme ji-k-line">
                    </i>
                    本周发布:<span><?php get_week_post_count(); ?> </span>               </li>
                <!--运行天数-->
                <li>
                    <i class="jitheme ji-artboard--line">
                    </i>
                    运行天数:<span><?php echo floor((time()-strtotime("2022-10-30"))/86400); ?></span>               </li>
            </div>
        </div>
    </div>
</div>

位置自行调整

css代码

/*统计模块*/
.jitheme_slide_n ol,ul,li{list-style:none;}
.jitheme_slide_tjmk{background:#586ce9;height:50px;}.jitheme_slide_tjmk .jitheme_slide_tj{height:20px;line-height:20px;text-align:center;padding:15px 0 12px}.jitheme_slide_tjmk .jitheme_slide_tj li{display:inline-block;line-height:20px;height:20px;padding-left:20px;position:relative;color:#fff;padding-right:20px;font-size:13px;}
/*结束*/

部分文章/资源来源于网络,文章标题下部均已标注来源,如有侵权,请点击此处联系客服进行删除,本站将会在第一时间内进行处理! 

如果您要搬运本站文章,请在文章底部标注。侵删请致信:663829289@qq.com

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系本站进行处理。

图床支持:https://space.simao58.cn/

如果文章帮助到您,还请您点击一下广告支持本站一下!

给TA打赏
共{{data.count}}人
人已打赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索

Warning: error_log(/www/wwwroot/ailketop.com/wp-content/plugins/spider-analyser/#log/log-2608.txt): failed to open stream: No such file or directory in /www/wwwroot/ailketop.com/wp-content/plugins/spider-analyser/spider.class.php on line 3014