Support » Fixing WordPress » Multiple loops break with this bit of code, any ideas why?

  • Resolved pineconez


    Commenting out the .images div will make the loops function properly, but with this code, the second loop will not function correctly.

    Specifically: the second (main) loop disregards “blog pages show at most”, and clicking a post link wont link to the specified post, but to all posts.

    First loop

    <?php $my_query = new WP_Query('showposts=8&offset=0'); ?>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <div class="posts" onclick="location.href='<?php echo get_permalink() ?>';" style="cursor: pointer;" class="fader">
            <div class="texts2">
                 <span><h3><?php the_title(); ?></h3></span>
            <div class="images">
    	    <?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'small'); if (has_post_thumbnail()) { echo '<img class="circles" src="'.get_bloginfo('template_url').'/timthumb.php?src='.$thumbnail[0].'&w=94&h=94&zc=1&q=100" alt="'.get_the_title().'" />';  }?>
    <?php endwhile; ?>

    Second (main) loop

    <div id="blogs">
    	<?php rewind_posts();?>
    	<?php if (have_posts()) : ?>
             <?php while (have_posts()) : the_post();?>
                    <div class="post">
                   	<h2><?php the_title(); ?></h2>
                   	<div class="content"><?php the_content(); ?></div>
              <?php endwhile; ?>

    Does anyone have any idea why the code within .images is breaking the next loop?
    Am I forgetting to close something? I just need a few other pairs of eyes here! Thanks!

    ps. the loop in question here, is using the script timthumb to pull the featured images from the posts, I am using it to make a visual wall of post images.

Viewing 2 replies - 1 through 2 (of 2 total)
  • codingpet


    Which second loop do you mean? The codes you showed works fine. If you have another loop below the codes you showed, then you need to add <?php wp_reset_query(); ?> to reset the query. Does it work?



    Oh man, you’re the best! Just the second eyes that I needed.
    I was using <?php rewind_posts();?>, and neglected <?php wp_reset_query(); ?>.

    I’ve updated the original post to show both loops as they were. Is rewind_posts(); even necessary in this case?

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple loops break with this bit of code, any ideas why?’ is closed to new replies.