[英]Show all post titles under the subcategories of a specific parent category in Wordpress
I have searched high and low for answers which is related to this code, however everytime i use this, it only shows the 5 recent post titles. 我在上下搜索了与此代码相关的答案,但是每次我使用它时,它仅显示最近的5个帖子标题。 What I wanted to do is show ALL post titles instead of the 5 recent post titles.
我想做的是显示所有帖子标题,而不是最近的5个帖子标题。
$categories = get_categories('child_of=3');
foreach ($categories as $category) {
//Display the sub category information using $category values like $category->cat_name
echo '<h2>'.$category->name.'</h2>';
echo '<ul>';
foreach (get_posts('cat='.$category->term_id) as $post) {
setup_postdata( $post );
echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>';
}
echo '</ul>';
}
In your get_posts
call, try supplying the posts_per_page
parameter. 在您的
get_posts
调用中,尝试提供posts_per_page
参数。
So: 所以:
foreach (get_posts('cat='.$category->term_id.'&posts_per_page=-1') as $post) {
a value of -1 will return all posts in the category. 值为-1将返回该类别中的所有帖子。
See the get_posts page of the Codex for more detail. 有关更多详细信息,请参见食典的get_posts页面 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.