I have categories driven site. I have different template for each category. I would like to set different number of posts – different for each category. Plus I would like to add proper previous and next links in each category.

for example in this category-1.php I want 4 posts per page:

<?php query_posts('showposts=4'); ?>
<a href="https://wordpress.stackexchange.com/questions/47861/<?=next_posts()?>"> PREVIOUS </a>
<a href="<?=previous_posts()?>"> NEXT </a>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
...
<?php endwhile; endif; ?>

but in this example next_posts() and previous_posts() doesn’t work.

5 s
5

As @StephenHarris pointed out there’s also the pre_get_posts filter.

function hwl_home_pagesize( $query ) 
{
    if ( is_category( 9 ) ) 
    {
        // If you want "posts per page"
        $query->query_vars['posts_per_page'] = 1;
        return;
    }
    if ( is_category( 'movie' ) )
    {
        // If you want "showposts"
        $query->query_vars['showposts'] = 50;
        return;
    }
}
add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );

Example altered from Codex example.

Leave a Reply

Your email address will not be published. Required fields are marked *