这就是我在某些类别下迭代所有wordpress帖子的方式。它每个类别只给我10个帖子。
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<a href="<?php echo get_permalink(); ?>">
<?php the_Title(); ?>
</a>
</li>
<?php endwhile; ?>
</div>
</ul>
<?php the_posts_navigation(); ?>
如何增加此限额?
这是我到目前为止所尝试的。
<?php while ( have_posts(array('posts_per_page' => '20')) ) : the_post(); ?>
它没有按预期工作。有什么帮助吗?
答案 0 :(得分:0)
每页更改限制
转到wp-admin然后
wp-admin -> Settings -> Reading -> Blog pages show at most (defult is 10. you can change your pagination per page limit here.) -> Save Changes
或
<?php
$post_type = 'post'; //your post type name here
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_args=array(
'type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => 20,
'paged' => $paged,
'caller_get_posts' => -1,
'child_of' => 0,
'parent' => 0,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'pad_counts' => false,
);
$post_my_query = null;
$post_my_query = new WP_Query($post_args);
if( $post_my_query->have_posts() ) :
?>
<ul>
<?php
while ($post_my_query->have_posts()) : $post_my_query->the_post();
?>
<li>
<a href="<?php echo get_permalink(); ?>">
<?php the_Title(); ?>
</a>
</li>
<?php
endwhile;
?>
</ul>
<?php
else :
echo '<p>No Post Found!</p>';
endif;
wp_reset_query($post_my_query);
the_posts_navigation();
?>