Forums

[resolved] Sidebar loop overwrites main loop (3 posts)

  1. BK_@_UC
    Member
    Posted 1 year ago #

    When you use multiple loops - like a custom loop in your side bar, it may overwrite your main loop... After troubleshooting where the problem was occurring and trying rewind_loop() unsuccessfully I found that starting a new loop would do the trick...

    while (have_posts()) : the_post();
       //the_content() was getting overwritten when by itself
       //but when enclosed with the while() statement
       //it works properly
       the_content();
    endwhile;

    This works, but Im not sure if this is best practice, if you have any follow up suggestions feel free to post...

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

  3. BK_@_UC
    Member
    Posted 1 year ago #

    Great... wp_reset_query was the answer! Thanks much...

    http://codex.wordpress.org/Function_Reference/wp_reset_query

    <?php wp_reset_query(); ?>

    or

    <?php
    query_posts('posts_per_page=5');
    if (have_posts()) : while (have_posts()) : the_post();
    	?><a href="<?php the_permalink() ?>"><?php the_title() ?></a><br /><?php
    endwhile; endif;
    wp_reset_query();
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic