Support » Fixing WordPress » Querying all posts

  • Resolved haagendazs1


    Hi, I feel this problem is probably has a really simple solution but I’ve been trying for hours and nothing is working…

    I have a dropdown menu of each category, and each item in the menu would lead you to each category’s archive. I just want a page that displays every post, and that would be considered the “all” category. Obviously I don’t want to actually create an “all” category and mark every post as having this category. Is there some code snippet I can stick in category.php (which is the template I’m using to display the category archives) that can say something to the effect of “if I’m on (some page or some empty category) display every post”?


Viewing 12 replies - 1 through 12 (of 12 total)
  • I forgot to mention what I’ve tried. The closest I got to getting it, is by doing this: I made a new page, ID=5, and made it use the category.php as its template. Then I made up a random category to exclude in query_post (lets say ID=5). Then, in category.php, before The Loop, I inserted something like this:

    <?php if (is_page(‘5’)) : ?>
    <?php query_posts(“cat=-5”.”&posts_per_page=12″); ?>
    <?php endif; ?>

    This almost got the effect I wanted, since it just made a category page, essentially, that excluded a category that has nothing in it. However, when I pressed the previous page links, the 12 posts shown in that previous page were identical to the 12 posts shown in the first page. For some reason, every page would only show the 12 most recent posts instead of going further back and actually showing the last 12 posts, then the 12 before that, etc.

    1. Isn’t your index (main, front) page doing just like that – showing “ALL”?

    2. Usually, query_posts breaks the next/prev navigation.

    1. Yes, it is. However I want a different page to be doing it as well, as an archive. Any ideas? 🙂

    2. Dang. 🙁

    1. Why would you want “duplicate content” – which, allegedly, is penalized by search engines?

    1. Ohh I don’t want to repost the whole post in the archives, its only the title and some stuff from each post’s custom fields, like the post’s rating or something like that.

    Anyone have any ideas? 🙁

    Could you use query_posts('posts_per_page=-1'); and not worry about prev/next navigation?

    Or develop your own loop using the wpdb class and deal with the next/prev navigation in your logic.

    You could create a Page (Write > Write Page) called… Category that just uses a custom Page template implementing query_posts().

    I do something similar on my site but don’t list every post! Just the categories with description and such. However, one can combine the idea of a Category Page with what I do on my ‘Archive’ Page:

    $limit = get_option('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('showposts=' . $limit . '&paged=' . $paged);
    $wp_query->is_archive = true; $wp_query->is_home = false;


    $limit is assigned the ‘posts_per_page’ option from your WordPress settings, but can be changed to something else if you like:

    $limit = 20;


    $wp_query->is_archive = true;
    $wp_query->is_home = false;

    after the query_posts() are important as they force posts_nav_link() (and so pagination) to work, along with a few other helpful results gained for fooling WordPress into thinking we’re in the archive pages.

    For the $paged stuff, see:

    Kafkaesqui: Thank you so much! Your method worked like a charm, I really appreciate your explanation.

    MichaelH: Thanks for the tips, I suppose I could have done the posts_per_page=-1 method if I didn’t have an alternative. I’ll keep your ideas in mind 🙂

    AWESOME POST! Worked Perfectly! BRAVO!!!!



    This is almost what I need.

    How can I exclude a couple of categories from this query?

    Thanks in advance!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Querying all posts’ is closed to new replies.