Forums

[resolved] query_posts -> Page 2 looks the same as Page 1 (5 posts)

  1. Anonymous
    Unregistered
    Posted 3 years ago #

    Hello,

    new - but nevertheless happy - WordPress user here. :-)

    I read through some of the documentation and examples of how to use query_posts() to only retreive posts from a certain category from the database and have them displayed on the front page. Like everything else in WP, it works fine and was easy to set up. But...

    If WP returns more than 10 pages and displays the "Next Page"/"Previous Page" links, the previous page, which should return older posts than those on the first page, shows the same pages as the first one.

    I tried this in two different themes (Box-Set and the default WP theme) and it happened both times, so it doesn't seem to be a problem with the theme I am using.

    All I did was insert a "query_posts('cat=16')" prior to the loop. Did I forget something?

    Thanks in advance,
    Thomas

  2. rmk80
    Member
    Posted 3 years ago #

    Hi,

    try this instead:

    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=16&paged=$page");

    see if this solves it!

  3. Anonymous
    Unregistered
    Posted 3 years ago #

    This seems to work fine, yes. Thanks alot!

  4. andrewfox
    Member
    Posted 3 years ago #

    This was an issue that was doing my head in. Thanks for this!

  5. Otto
    Tech Ninja
    Posted 3 years ago #

    A better solution is to include the original query string in your query, then override the bits you want. Like so:
    query_posts($query_string . "&cat=16");

Topic Closed

This topic has been closed to new replies.

About this Topic