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 am trying to output all the posts of a certain category but all that is happening is The page content is being outputted no posts?

template page

Template Name: Blog

<?php get_header(); ?>

            <div id="content">

                <div id="inner-content" class="wrap clearfix">

                    <div id="main" class="eightcol first clearfix" role="main">

                   <?php $query = new WP_Query( 'category_name=blog' ); ?> 

                        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                        <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">

                            <header class="article-header">

                                <h1 class="page-title"><?php the_title(); ?></h1>
                  <p class="byline vcard"><?php
                    printf(__('Posted <time class="updated" datetime="%1$s" pubdate>%2$s</time> by <span class="author">%3$s</span>.', 'bonestheme'), get_the_time('Y-m-j'), get_the_time(__('F jS, Y', 'bonestheme')), bones_get_the_author_posts_link());

                            </header> <!-- end article header -->

                            <section class="entry-content">
                                <?php the_content(); ?>
                            </section> <!-- end article section -->

                            <footer class="article-footer">
                                <p class="clearfix"><?php the_tags('<span class="tags">' . __('Tags:', 'bonestheme') . '</span> ', ', ', ''); ?></p>

                            </footer> <!-- end article footer -->

                            <?php comments_template(); ?>

                        </article> <!-- end article -->

                        <?php endwhile; ?>  

                        <?php else : ?>

                            <article id="post-not-found" class="hentry clearfix">
                                <header class="article-header">
                                    <h1><?php _e("Oops, Post Not Found!", "bonestheme"); ?></h1>
                                <section class="entry-content">
                                    <p><?php _e("Uh Oh. Something is missing. Try double checking things.", "bonestheme"); ?></p>
                                <footer class="article-footer">
                                    <p><?php _e("This is the error message in the page-custom.php template.", "bonestheme"); ?></p>

                        <?php endif; ?>

                    </div> <!-- end #main -->

                    <?php get_sidebar(); ?>

                </div> <!-- end #inner-content -->

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

<?php get_footer(); ?>
share|improve this question
You're using WP_Query incorrectly. See my answer for details. – shea Feb 1 '13 at 7:56

You are using WP_Query incorrectly: you need to be calling the have_posts() and the_post() functions as methods of your $query variable:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>


<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>

You should also call wp_reset_postdata(); after the query loop is finished.

Learn more about how to use the WP_Query class at the WordPress Codex.

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.