admin管理员组文章数量:1122846
I would like to change archives.php
post listing as follows.
Whenever clicked on certain link in archives select drop down box, archive page should list posts from May - Dec of that year, plus Jan - April of next year.
Eg. If i clicked on archives drop down, 2015...Archives page /2015/
will list all posts from the database starting from May 2015 to December 2015, also January 2016 to April 2016. This is to display posts in an annual year in the calendar.
My current wp archive have posts code like below;
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
// End the loop.
endwhile;
I would like to change archives.php
post listing as follows.
Whenever clicked on certain link in archives select drop down box, archive page should list posts from May - Dec of that year, plus Jan - April of next year.
Eg. If i clicked on archives drop down, 2015...Archives page http://domainname.xyz/2015/
will list all posts from the database starting from May 2015 to December 2015, also January 2016 to April 2016. This is to display posts in an annual year in the calendar.
My current wp archive have posts code like below;
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
// End the loop.
endwhile;
Share
Improve this question
edited Apr 9, 2016 at 11:41
yjs
asked Apr 9, 2016 at 10:21
yjsyjs
515 bronze badges
1 Answer
Reset to default 0It depends on how your archives.php
is designed.
You can use built-in wp_get_archives()
function to get posts for last 12 months:
<?php
wp_get_archives(
array(
'type' => 'monthly',
'limit' => 12
)
);
as described in the Codex.
Or you can modify the WP_Query
using 'date_query'
parameter:
<?php
$args = array(
'date_query' => array(
array(
'after' => strtotime("-1 year"), // a year before
'before' => strtotime("now");, // now
'inclusive' => true, // false to exclude first and last day
)
)
);
$query = new WP_Query( $args );
as also described there.
本文标签: How can I change archivephp posts display
版权声明:本文标题:How can I change archive.php posts display? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294844a1929444.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论