0

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?

2 Answers 2

4

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.

1
0

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.

3
  • 1
    You should edit/update your original answer with this. Commented Sep 16, 2011 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. Commented Sep 16, 2011 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
    Commented Sep 16, 2011 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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