Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I was working on this site this morning and I ran into a bit of an issue with my static page.

I have a "featured" post section and I use:

<div id="featured">
    <img src="<?php echo get_bloginfo('template_directory'); ?>/images/house.jpg" alt"Buy Me" />

    <div class="info">
     <?php query_posts(array ('tag'=> 'featured' )); ?>
    <?php while (have_posts()) : the_post(); ?>

    <h1><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></h1>
    <p><?php the_time('F jS, Y') ?> by <?php the_author() ?></p>
    <?php endwhile; ?> 

    </div>

</div>

The above works great, however, the page content is where I am running into an issue. I have a content section that is pulling in the "pages" actual content, and I use:

<div id="about">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">

            <h2><?php the_title(); ?></h2>


            <div class="entry">
                <?php the_content(); ?>
            </div>


        </div>

    <?php endwhile; ?>

    <?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>

    <?php else : ?>

        <h2>Not Found</h2>

    <?php endif; ?>


</div>

When I refresh the page, both of the sections are now displaying the featured post, and not the the page content. Does anyone have a clue to why this is happening?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

You're using query_posts() for your featured-post custom loop. As the Codex says: don't do that.

The query_posts() function is intended to modify the Primary Loop. If you need a custom loop, use e.g. $my_custom_query = new WP_Query( $args ).

See here for a good break-down of custom-loop options.

share|improve this answer
    
Rarst has a good diagram here: When should you use WP_Query vs query_posts() vs get_posts()? –  Brian Fegter Sep 16 '11 at 14:54

Thanks Chip. I rewrote it after reading your reply as:

<?php $featured_query = new WP_Query( array ('tag'=> 'featured' ) ); ?>

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

    <h2><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></h1>

<?php endwhile;?>

<?php wp_reset_postdata(); ?>

Everything seems to be working just fine now. I appreciate the help.

share|improve this answer
1  
You should edit/update your original answer with this. –  Brian Fegter Sep 16 '11 at 14:55
    
Glad to help! Just for future reference: given the way WPSE is intended to work, this would be better posted as an update to your answer, since it's not really a separate answer. –  Chip Bennett Sep 16 '11 at 14:56
    
The ongoing updates should be added to a question, but a final working solution should be an answer and should be posted as such separately (obviously if it differs from other answers provided). –  Rarst Sep 16 '11 at 15:17

Your Answer

 
discard

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.