可以在你的网站上显示今日文章发布数量,总文章数量,以及用户注册数量
![图片[1]-WordPress网站添加文章统计 用户统计代码-星网科技 Grdy.cn](https://www.grdy.cn/king72/tupiaodaw/upiaori47/2024/09/01/44/5w0zdgw0vg4202409011944315w0zdgw0vg428065608666.png)
1.先把下方代码添加到你当前使用的模版的function.php文件里面
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 ); return $query->post_count;}// 每周日新function jiubgx() { $today = getdate(); $query = new WP_Query( \'year=\' . $today[\"year\"] . \'&monthnum=\' . $today[\"mon\"] . \'&day=\' . $today[\"mday\"]); $postsNumber = $query->found_posts; echo $postsNumber;}
2.添加下方代码到你想要显示的页面里面,一般 index 首页, footer是底部, header是头部 (代码文字可以自行修改或者添加美化)
//显示总文章数量<?php echo $publish_posts = wp_count_posts()->publish;?>//查询特定分类文章数量,比如我要查52分类<?php echo publish;echo $publish_posts-get_category(52)->count;?>//本周更新<?php echo get_week_post_count(); ?>//今日更新<?php echo jiubgx();?>
本站代码模板仅供学习交流使用请勿商业运营,严禁使用星网科技上的模板&源码从事违法,侵权等任何非法活动!
感谢您的来访,获取更多精彩文章请收藏本站。

暂无评论内容