• Resolved tdellaringa

    (@tdellaringa)


    I wanted to show only 1 post on my blog home page, but 10 on my archive/category pages. It was suggested I leave the options set to show 1 post, then add the following to my archive:

    <?php query_posts('showposts=10'); ?> <-- added this line
    <?php while (have_posts()) : the_post(); ?>

    This initially seemed to work, until I realized I was getting *all* of my posts on every archive (month) and category page. Removing the line fixes it back.

    Why does showposts pull *all* posts? In any event, is there another way I can accomplish showing multiple posts on my archive/category pages but still only 1 on the home blog page? I’m not using, nor do I want to use, a static home page.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    The reason it does this is because you’re overriding the default query string parameters.

    See, when WordPress starts up, it gets the URL/permalink and automatically figures out what the viewer is asking for. Archives, categories, etc. These become the “query string” and get passed to “query_posts”, which fetches the posts.

    However, you’re manually calling query_posts and giving it your own query_string. This changes what posts you get back. In order to keep the original settings, and only override the “showposts” part of the query string, you need to add to the existing query string instead of overwriting it entirely.

    And you do that like this:
    query_posts($query_string . "&showposts=10");

    Simple, huh? More examples and info here:
    http://codex.wordpress.org/Template_Tags/query_posts

    Read the whole thing, it’s worth it to understand what’s going on.

    Thread Starter tdellaringa

    (@tdellaringa)

    Thanks Otto, that does indeed work. Heading over right now to read that page 🙂

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

The topic ‘showposts breaks my archives – fix?’ is closed to new replies.