Wordpress - 如何在 archive.php 上仅返回当前月份的帖子 [英] Wordpress -how to return just current month posts on archive.php
问题描述
如何修改 wp_query 以根据 URL 2012/10/
按月接收计数帖子?
How to modify the wp_query to take in count post by month as per URL 2012/10/
?
下面将列出ALL帖子,我只想列出2012/10/
的帖子
The following will list ALL post, where I just want to list post for 2012/10/
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'posts_per_page' => 10, 'paged' => $paged, 'orderby' => 'date', 'order' => 'DESC' );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post();
非常感谢任何建议.
推荐答案
早先答案的链接中提供了一个代码片段,上面写着仅返回当前周的帖子".将周"更改为月",您就得到了答案.
There's a code snippet provided in the link from the earlier answer that says "Returns posts for just the current week". Change "week" for "month", and you got your answer.
代码片段如下所示:
$year = date('Y');
$month = date('n');
$query = new WP_Query( 'year=' . $year . '&monthnum=' . $month );
只需阅读链接.应有尽有.
如果返回月份还有其他问题,可能是因为变量需要 前导零.在这种情况下, $month 变量应该是
If there are further problems returning the month, it may be because the variable needs a leading zero. In that case, the $month variable should be
$month = date('m');
这篇关于Wordpress - 如何在 archive.php 上仅返回当前月份的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!