WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Loop Cancelled Out By Other Loop (5 posts)

  1. kennethwatt
    Member
    Posted 4 years ago #

    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

  2. muthukswamy
    Member
    Posted 4 years ago #

    Use <?php wp_reset_query(); ?> before making your call for next loop.
    Read more at: http://codex.wordpress.org/Template_Tags/query_posts

  3. kennethwatt
    Member
    Posted 4 years ago #

    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 :)

  4. muthukswamy
    Member
    Posted 4 years ago #

    Can you post the full code here.

  5. kennethwatt
    Member
    Posted 4 years ago #

    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 :)

Topic Closed

This topic has been closed to new replies.

About this Topic