0

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

0

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' );
  • 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

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.