2024年10月13日 建站教程
wordpress如何在网站首页显示本周的文章数量和当天的文章数量,下面web建站小编给大家简单介绍一下具体实现代码!
// 每周更新的文章数量
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 get_day_post_count() {
$today = getdate();
$query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"]);
$postsNumber = $query->found_posts;
echo $postsNumber;
}
<div> 本站共有:<?php echo $publish_posts = wp_count_posts()->publish; ?>篇文章, 本周更新:<?php get_week_post_count(); ?>篇文章, 今日更新:<?php get_day_post_count(); ?>篇文章 </div>
本文链接:http://so.lmcjl.com/news/15284/