WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multiple loops not working after 2.1 (4 posts)

  1. richardflynn
    Member
    Posted 7 years ago #

    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 &lsquo;<?php the_title(); ?>&rsquo;">Carry on reading &raquo;</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 &raquo;</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!

  2. richardflynn
    Member
    Posted 7 years ago #

    Just fixing the code in the original post

  3. richardflynn
    Member
    Posted 7 years ago #

    All right, talking to myself, I know! I've sorted this out. It turns out that the problem was with the Sideblog plugin. I've now updated the plugin to v. 3.5, and after having to reconfigure all my display options, everything is working as it should.

  4. Seaborn
    Member
    Posted 7 years ago #

    I am having a bit of a problem with mulitple loops and 2.1 as well. My code is almost exactly the same as yours and everything displays properly except my comments tag is not displaying. Any advice?

Topic Closed

This topic has been closed to new replies.

About this Topic