WordPress.org

Support

Support » Themes and Templates » [Resolved] Loop Cancelled Out By Other Loop

[Resolved] Loop Cancelled Out By Other Loop

  • Hi guys
    In my header, I have a list of recent posts. This should be controlled by its own loop:

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

    However, it shows whatever the page content is meant to be displaying; author pages showing the author’s posts, pages showing the page title, posts showing the post title.
    What should I change that code to to make sure it shows a list of the 6 latest posts?
    Thanks
    K

Viewing 4 replies - 1 through 4 (of 4 total)
  • Use <?php wp_reset_query(); ?> before making your call for next loop.
    Read more at: http://codex.wordpress.org/Template_Tags/query_posts

    Hi there
    Not working I’m afraid.
    It’s like the actual request the page is making for which ever post it’s on, cancels out the header loop :S
    Thanks anyway 🙂

    Can you post the full code here.

    Sorry, tweaked it a bit to this:

    <?php
    
    //The Query
    query_posts('showposts=5');
    
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title(); ?></a></li>
    <?php endwhile; else: ?>
     		<li>Something went bang... please try again later.</li>
    <?php endif;
    
    //Reset Query
    wp_reset_query();
    
    ?>

    Thanks 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Loop Cancelled Out By Other Loop’ is closed to new replies.
Skip to toolbar