admin管理员组文章数量:1332873
I am creating a theme, and have run into a problem with how a custom WP_Query seems to interact with the Blog pages show at most settings found under Settings -> Reading in the WordPress backend. I have a paged query, where - for layout reasons, I want to display 6 posts per page. My code looks like this:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged,
);
$loop = new WP_Query($args);
if ($loop->have_posts()):
while ($loop->have_posts()): $loop->the_post();?>
<div class="blogpost-div">
My blogpost goes here
</div>
<?php
endwhile;
else:
_e('There are currently no posts available.', 'textdomain');
endif;
echo custom_pagination($loop);
wp_reset_postdata();
?>
This works fine. However, if I have less than 6 published blog posts in my installation, this query displays no posts (Or if the next page doesen't have 6 posts, it 404s) unless the aforementioned reading setting is also set to be limited at 6 posts. This becomes an issue, if someone needs to install my theme on a fresh installation of WordPress, since they would then also need to adjust these settings.
In short - it seems, that when a custom query tries to modify posts_per_page
, and the total amount of posts generated by the query is less than the defined number of posts in posts_per_page
the query somehow conflicts with the "Blog pages show at most settings" if these aren't set to the same value.
Is this really intentional?
本文标签: wp queryBlog post per page setting conflicting with custom WPQuery
版权声明:本文标题:wp query - Blog post per page setting conflicting with custom WP_Query? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742310506a2450773.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论