可以在你的网站上显示今日文章发布数量,总文章数量,以及用户注册数量

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();?>
<p>目前为止我们有
<span class="counter">
<?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users; ?>
</span> 位会员,还有
<span class="counter">
<?php echo $publish_posts = wp_count_posts()->publish;?>
</span> 个精品资源!</p>
请先
!