RIPRO首页添加显示本周和今日更新的文章数量
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;?>
以上代码所显示的样式代码请自行根据站点的情况调整好,然后保存更新好文件.
END
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 部分资源为什么要收费?
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"www.shejicook.com",如遇到无法解压的请联系管理员!