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 am using the following query on my category.php template:

<?php
    $paged = (get_query_var("paged")) ? get_query_var("paged") : 1;
    query_posts("posts_per_page=2&paged=".$paged);
?>

The one thing that I've noticed is that this breaks my pagination...with this code the pagination returns "paged" in the url: http://example.com/?cat=12&paged=2, fortunately or unfortunately it's a simple issue with the url...instead of returning "paged" in the url, it should return "page" or http://example.com/?cat=12&page=2.

I have tried altering my code (as explained: http://codex.wordpress.org/Function_Reference/get_query_var for pages):

<?php
    $page = (get_query_var("page")) ? get_query_var("page") : 1;
    query_posts("posts_per_page=2&page=".$page);
?>

But that doesn't work either...any ideas?

Thanks,
Josh

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

paged is correct unless you're using pretty permalinks, however, if you're just trying to alter posts per page for categories, you should be using the pre_get_posts action, there's no reason to use query_posts in the template:

function wpa85791_category_posts_per_page( $query ) {
    if ( $query->is_category() && $query->is_main_query() )
        $query->set( 'posts_per_page', 2 );
}
add_action( 'pre_get_posts', 'wpa85791_category_posts_per_page' );
share|improve this answer
    
Milo, I am using query_posts simply to restrict the number of posts per page...how do I apply your fix to just my category.php template? –  Josh Rodgers Feb 13 '13 at 19:49
    
put that in your theme's functions.php file. –  Milo Feb 13 '13 at 19:50
    
It works!! Thanks so much! –  Josh Rodgers Feb 13 '13 at 19:53
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.