1. 将以下代码添加到主题 functions.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 ); 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; }
其中 get_week_post_count()是统计每周更新的文章数量并输出,WeeklyUpdate()是统计每日更新的文章数量并输出。
2. 将以上两个函数添加到想要输出每周更新和每日更新的文章数量处即可,如添加到首页 index.php 文件中。
<div class="gengxin" style="width: 100%; height: 40px; line-height: 40px; text-align: center; box-shadow: 0 0 10px rgba(0,0,0,.05); background-color: #ffffff; margin-bottom: 10px;">本站共有:<!--?php echo $publish_posts = wp_count_posts()->publish;?--> 篇文章(其中 WordPress 分类有<!--?php echo get_category(1)->count;?--> 篇文章), 本周更新:<!--?php get_week_post_count(); ?--> 篇, 今日更新:<!--?php WeeklyUpdate();?--> 篇</div>
其中
//输出站点总的文章数量 <?php echo $publish_posts = wp_count_posts()->publish;?> //查询特定分类的文章数量,如我要查 WordPress 分类(ID=1)文章数 <?php echo get_category(1)->count;?>
以上代码所显示的样式代码请自行根据站点的情况调整好,然后保存更新好文件.
小白小心食用!
转自计划书之家
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。