• hello,

    So I’m working on this site:
    https://dev.perspectivescs.org/?page_id=21

    and here’s the deal: I keep using css to position things on the page in the right sequence, because I keep having to move the code around. The reason is that there are three or four loops here — the ‘hear our stories’ on the left, the page content in the middle, the news and calendar in the right bar, and the breadcrumb at the foot. I have the breadcrumb calling at the top of the page and just positioning itself at the bottom, because when i put it at the bottom it’s filtered by the news loop (so it always says home > news). Other loops dont seem to work in certain order as well. So my question is, how does one clear the filter from a previous loop?

    I have a number of filters like this:

    <?php query_posts('cat=3')?>

    and I think these queries are screwing things up.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter public_radio

    (@public_radio)

    I’m afraid i’m not getting anything from this article… I’ve tried clearing the post cache before breadcrumb(); but it doesn’t seem to do anything. There has to be a way to get breadcrumb(); to work properly.

    Let me show you what loops I’m using, paraphrased:


    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    <?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
    <?php endwhile; endif; ?>

    Loop2:


    <?php query_posts('cat=3'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_date('','<div class="urgentdate">','</div>'); ?>
    <?php the_content(__('&raquo;<span>&nbsp;</span>')); ?>
    <?php endwhile; endif; ?>

    Loop3:


    <?php query_posts('cat=4'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_excerpt_reloaded('100','<strong><img>'); ?>
    <?php endwhile; ?>

    …and in this order everything works (but if the first loop is last then it doesn’t work because the query_posts() don’t clear. And then there’s this:


    <?php breadcrumb(); ?>

    And this breadcrumb doesn’t work because of the query_posts() from the other loops. There has to be a way to reset this. It seemed like the multiple loops in that codex didn’t apply to this situation. Anyone?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Just before you call your breadcrumb thingy, do this:
    query_posts($query_string);

    That will reset the query back to the same one as you had before any loop.

    This recent topic hits on the same issue:

    https://www.ads-software.com/support/topic/91067

    Basically, to avoid whacking the default posts object on a page, avoid use of query_posts() (which is best used to reset the default posts loop) and go with creating a new WP_Query instance, so that:

    Loop 2 starts:
    <?php $cat_query = new WP_Query('cat=3'); ?>
    <?php if ($cat_query->have_posts()) : while ($cat_query->have_posts()) : $cat_query->the_post(); ?>

    Loop 3 starts:
    <?php $cat_query = new WP_Query('cat=4'); ?>
    <?php if ($cat_query->have_posts()) : while ($cat_query->have_posts()) : $cat_query->the_post(); ?>

    Thread Starter public_radio

    (@public_radio)

    Thank you very much, but these solutions didn’t work for the breadcrumb.

    I’ll tell you what did work, in case anyone wants to know:

    If you need to put a breadcrumb in the footer but the loops that precede it screw it up, call the breadcrumb once in the header, in a display:none div, then call it again at the footer. It seems to remember the results it extracted from the top.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘trouble killing/resetting loops’ is closed to new replies.