WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multiple loop issues, two variations, neither work. (3 posts)

  1. Vagari
    Member
    Posted 7 years ago #

    I have a multiple loop on the front page that works fine for spitting out a few "recent posts." But I need to same thing in a "sidebar" on some internal pages. The original code does not work because of whatever bug is breaking the multiple loops. is_page() stops working correctly.

    http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_2

    Here's that code.

    $temp_query = clone $wp_query;
    query_posts('showposts=5'); ?>
    <h3 class="">Recent Posts</h3>
    <ul id="rec_post_list">
    <?php while (have_posts()) : the_post(); ?>
    	<li><h4><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></h4>
    	<p><?php the_time('F jS, Y') ?> · <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p></li>
    <?php endwhile; ?>
    </ul>
    <?php $wp_query = clone $temp_query; // And back to normal...

    Since it used to work I really wish it wasn't broken. Nice and simple. But I figured I'd comment it out and try another version. This one worked, for the most part, no breaking of "is_page" and stuff like that. But NOW I can't get comments_popup_link to work.

    <?php $my_query = new WP_Query('showposts=5'); ?>
    <h3 class="">Recent Posts</h3>
    <ul id="rec_post_list">
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    	<li><h4><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></h4>
    	<p><?php the_time('F jS, Y') ?> · <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p></li>
    <?php endwhile; ?>
    </ul>

    It's basically the same code with just the different method for grabbing the query. Does anyone know why the comments_popup_link() doesn't work anymore? the_title() and the_permalink() work fine. And I really need to get this fixed. I'm almost done with the site and I'm running out of unrelated things to do.

    Thanks everyone!

  2. Vagari
    Member
    Posted 7 years ago #

    OK, so since I'm trying to get this to work on an individual page according to the documentation it won't work, "even when within The Loop."

    http://codex.wordpress.org/Template_Tags/comments_popup_link

    Makes sense if this is THE loop for the page. But this is an alternate "loop." Anyone have any idea how to get around this? Or an alternative for multiple loops that would provide me with what I need and still allow this stuff?

    Here's the basics of the layout... I'll try my best in unformatted text.

    Recent Posts

    Title of article one.
    April 12th, 2007 · No Comments

    Title of Article two.
    April 5th, 2007 · 3 Comments

    Title of Article three.
    April 1st, 2007 · 1 Comment

    It's nothing fancy. Thanks again everyone.

  3. Vagari
    Member
    Posted 7 years ago #

    I'd be interested in other solutions to this problem. But a workaround I've found is to use comments_number() (which isn't exactly the same statistic) and manually create the URL.

    <a href="<?php comments_link(); ?> "><?php comments_number('No responses','One response','% responses'); ?></a>

Topic Closed

This topic has been closed to new replies.

About this Topic