Multiple loops not working after 2.1
-
Hi all, another question brought about by an upgrade to 2.1…
Following the example of the Codex, I have multiple loops on my homepage, so that an extract is printed for the first post, and the title/date/number of comments is printed for the following six posts.
The relevant portion of my home.php template is coded as follows:
<div id="latest-writing" class="home-inner-div new">
<h1>Latest Writing</h1>
<?php $my_query = new WP_Query('showposts=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<h2><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<ul class="postmetadata">
<li class="read-more"><a href="<?php the_permalink() ?>" title="Read ‘<?php the_title(); ?>’">Carry on reading »</a></li>
<li class="comments"><?php comments_popup_link('No comments', 'One comment', '% comments'); ?></li>
<li class="date"><?php the_time('jS M Y') ?></li></ul>
<?php endwhile; ?>
</div><!--/latest-writing-->
<div id="more-writings" class="home-inner-div new">
<h1>Other Recent Writings</h1>
<dl class="itemlist">
<?php $my_query = new WP_Query('&showposts=6');
while ($my_query->have_posts()) : $my_query->the_post();
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<dt><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></dt>
<!--/the <dd>s are in the following order of right-to-left because they float right-->
<dd class="read-article"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">Read »</a></dd>
<dd class="comments"><?php comments_popup_link('No comments', 'One comment', '% comments'); ?></dd>
<dd class="date"><?php the_time('jS M Y') ?></dd>
<?php endwhile; ?>
</dl>
</div><!--/more-writings-->
This worked just fine until I upgraded to 2.1. Now, as you can see at http://richardflynn.net, it prints the extract of the first post just fine, but then in the list of other recent posts it repeats the data for the second post three times before conking out. It should of course list the second-, third-, fourth-, fifth-, and sixth-most-recent posts in that
<div>.Has anyone got a suggestion for how this could be fixed, or could posit a reason why this is broken in 2.1? I hope I’ve provided enough information!
The topic ‘Multiple loops not working after 2.1’ is closed to new replies.