• I want to set my index page to show only posts from a certain category which I was able to satisfactorily accomplish using the query_posts option.

    The problem is that when I click on the next or previous post links it doesn’t take me to the next page…just keeps looping me back to the first set of posts viewed.

    Anyone know a fix for this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think this is because you’ve used this format..

    query_posts( 'cat=3' );

    Although this would be correct for selecting all posts in category 3, it doesn’t account for any cases when your file (index.php or whatever it be, the same applies for other files) is being passed any query vars. This may not be a problem if you have several other template files handling those query variables (examples would be, author, category, month, week, day and so on..)..

    So what happens is, when a query variable gets set (a request is sent for one), and a file is selected to deal with that particular variable, if you make any changes to the query_posts line, you essentially lose all queried parameters… (unless you pass these into the query_posts line).

    In this case the paged query_var is not being passed along into the query.

    To fix the problem…

    // Sets a variable defined by the paged query var, if it doesn't exist, then we know it's page 1
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    query_posts( 'YOURARGS&paged='.$paged );

    Where “YOURARGS” are you current query arguments/parameters …

    Hope that helps..

    Thread Starter raimy

    (@raimy)

    That’s the ticket!! Thanks for your help and for the explanation. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘query_posts and navigation’ is closed to new replies.