WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to display all posts from specific categories on a single page. Therefore I edited the page.php file in my theme folder. I added an 'if-clause' to check which page currently being displayed and load all posts from the following categories.

<?php get_header(); ?>

<div id="primary">
    <div id="content" role="main">

    if (is_page(26)) {
        if (have_posts()) : 
            while (have_posts()) : 
                get_template_part( 'content', 'page' );
    } else {
        while ( have_posts() ) : 
            get_template_part( 'content', 'page' ); 
        endwhile; // end of the loop. 

    </div><!-- #content -->
</div><!-- #primary -->

<?php get_footer(); ?>

But when I load my page 26 nothing will be displayed.

share|improve this question
Don't use query_posts wordpress.stackexchange.com/a/50762/10911. Use WP_Query for this codex.wordpress.org/Class_Reference/WP_Query – janw Jan 2 '13 at 11:47
up vote 2 down vote accepted

I'd Advise adding the arg of the category in an array. And don't use query_posts. Also showposts is deprecated use posts_per_page instead.

$args = array (
    'cat' => array(2,6,9,13),
    'posts_per_page' => -1, //showposts is deprecated
    'orderby' => 'date',

$cat_posts = new WP_query($args)

if ($cat_posts->have_posts()) : while ($cat_posts->have_posts()) : $cat_posts->the_post(); 
        get_template_part( 'content', 'page' );
endwhile; endif;  
share|improve this answer

This happens because you are still using query_posts(). Stop doing that. Use WP_Query instead:

$extra_posts = new WP_Query( 'cat=2,6,9,13&showposts=-1&orderby=date' );
if ( $extra_posts->have_posts() )
    while( $extra_posts->have_posts() )
        get_template_part( 'content', 'page' );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.