Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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(); ?>
        </a> 
        <?php echo get_link_excerpt(); ?>
    </li>
<?php endwhile; } ?>
share|improve this question
    
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
add comment

3 Answers 3

up vote 2 down vote accepted

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) {
   do_something-with($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.)

share|improve this answer
    
This is exactly what I was looking for. Thanks! –  Scott B Feb 9 '11 at 18:11
    
Glad to hear it! –  editor Feb 9 '11 at 19:32
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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