• How do I query all posts rather than just by a specific category or tag? etc.

    Basically I have a page that uses a custom template. On it I would like to pull in all of the posts for a site. If I use the standard:

    <?php if(have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    Then it just gets the content for that particular page.

    Is there some way I can use the query_posts function to do this?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try adding:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'posts_per_page' => -1,
    	'paged' => $paged
    );
    query_posts($args);
    ?>

    just before the start of the Loop.

    Thread Starter 000000000

    (@pealo86)

    thanks, but I ended up getting it to work by passing ‘showposts=-1’ as a parameter.

    pealo86,
    showposts parameter is deprecated. Use posts_per_page instead. e.g ‘posts_per_page=-1

    esmi,
    ‘paged’ is not required since ‘posts_per_page=-1‘ will show all post in a single page.

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