admin管理员组文章数量:1330590
I am developing my first Wordpress theme. I've created a custom page for a specific post category, and I would like to display all the posts from this specific category on the page.
The code is largely borrowed from elsewhere, so it's highly likely that it's not best practice, but it seems to be working. However, there is one fairly significant problem:
The code I'm using limits the number of posts to the first ten (sorted by alphabetical order). Could anyone tell me how I can change the code I've written so that all of the posts in this category will be displayed?
Any help would be very greatly appreciated!
<?php
$r = new WP_Query(
apply_filters(
'widget_posts_args',
array(
'post_status' => 'publish',
'cat' => 5,
'orderby' => 'title',
'order' => 'ASC',
),
$instance
)
);
if ( ! $r->have_posts() ) {
return;
}
?>
<ul>
<?php foreach ( $r->posts as $hof_post ) : ?>
<?php
$post_title = get_the_title( $hof_post->ID );
$title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
$thumbnail = get_the_post_thumbnail($hof_post->ID);
$excerpt = get_the_excerpt($hof_post->ID);
$aria_current = '';
?>
<li>
<a href="<?php the_permalink( $hof_post->ID ); ?>">
<?php echo $thumbnail; ?>
<h3><?php echo $post_title ?></h3>
<p><?php echo $excerpt ?></p>
</a>
</li>
<?php endforeach; ?>
</ul>
I am developing my first Wordpress theme. I've created a custom page for a specific post category, and I would like to display all the posts from this specific category on the page.
The code is largely borrowed from elsewhere, so it's highly likely that it's not best practice, but it seems to be working. However, there is one fairly significant problem:
The code I'm using limits the number of posts to the first ten (sorted by alphabetical order). Could anyone tell me how I can change the code I've written so that all of the posts in this category will be displayed?
Any help would be very greatly appreciated!
<?php
$r = new WP_Query(
apply_filters(
'widget_posts_args',
array(
'post_status' => 'publish',
'cat' => 5,
'orderby' => 'title',
'order' => 'ASC',
),
$instance
)
);
if ( ! $r->have_posts() ) {
return;
}
?>
<ul>
<?php foreach ( $r->posts as $hof_post ) : ?>
<?php
$post_title = get_the_title( $hof_post->ID );
$title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
$thumbnail = get_the_post_thumbnail($hof_post->ID);
$excerpt = get_the_excerpt($hof_post->ID);
$aria_current = '';
?>
<li>
<a href="<?php the_permalink( $hof_post->ID ); ?>">
<?php echo $thumbnail; ?>
<h3><?php echo $post_title ?></h3>
<p><?php echo $excerpt ?></p>
</a>
</li>
<?php endforeach; ?>
</ul>
Share
Improve this question
asked Jul 17, 2020 at 16:38
Tom DaviesTom Davies
232 bronze badges
1 Answer
Reset to default 110 is the default page length which is taken from the Wordpress settings.
It's a little bit hidden but there in the docs for WP Query there's a parameter posts_per_page
which can be set to -1
to get all posts, so you just need to add that to the arguments to pass to WP_Query.
(If that doesn't work and you copied that WP_Query code from somewhere, you might need to remove the apply_filters() part and just keep the inner array()
and pass that directly to WP_Query)
本文标签: categoriesWhy is this category page limiting the number of posts
版权声明:本文标题:categories - Why is this category page limiting the number of posts? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742254051a2441299.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论