I'm using this script on my archive.php in order to list a link list of all posts contained in the current category. However, its limiting the result count relative to the number assigned to "Settings > Reading > Blog Pages Show At Most _ posts".

In other words, there may be 10 posts that are in this category, but its only displaying up to the number assigned in that setting.

How can I change my script to ignore this setting?

<?php if(is_category()) while (have_posts()) : the_post(); ?>
    <li id="post-<?php the_ID(); ?>">
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
        <?php the_title(); ?>
        <?php echo get_link_excerpt(); ?>
<?php endwhile; } ?>
  • To the person who voted this down, I'm sure you had a valid reason in the spirit of improving the question, but please at least take the time to comment on how the question could be improved. – Scott B Feb 9 '11 at 18:13

Instead of using the default loop, perhaps try building your own query.

Basically, it'll look something like this:

$your_posts = get_posts('cat=123&posts_per_page=123');
foreach ($your_post as $post) {

You can display all posts by either use the param 'posts_per_page'=>-1 or nopaging=true.

(Not sure why someone voted this down? IMHO said person should comment on how the question should be improved if she or he is going to do that.)

  • Glad to hear it! – editor Feb 9 '11 at 19:32

To modify the posts_per_page setting on a contextual basis, the best approach is to filter the query via callback to pre_get_posts. For example, to set posts_per_page to 10 for a specific category (say, category ID 7):

function wpse8982_filter_pre_get_posts( $query ) {
    if ( $query->is_main_query() && is_category( 7 ) ) {
        $query->set( 'posts_per_page', '10' );
add_action( 'pre_get_posts', 'wpse8982_filter_pre_get_posts' );

Note that you can pass any valid setting for posts_per_page.


If you want to do something other than the automagical defaults allow for, you need to take control of your Loop. Read the docs on The Loop and take particular notice of the section labeled Multiple Loops. It shows alternate ways of setting up the query and displaying things. You should also take a look at WP_Query as that is key to what is going on here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.