WordPress.org

Ready to get started?Download WordPress

Forums

Mini-loop won't rewind since 2.8 upgrade (4 posts)

  1. dvsmith
    Member
    Posted 5 years ago #

    On the site I run, we list upcoming events in our sidebar, using a mini-loop.

    Since upgrading to 2.8.x, it seems that the mini loop won't rewind, so the last listed event's the_title overwrites whatever page or post you're looking at (amongst other items on the page).

    Either something is broken with WordPress, or the way I'm calling these items.

    Here's the code, which worked under 2.7.x and earlier:

    <ul>
    	<?php
    		$future_events = new WP_Query('category_name=Calendar&post_status=future&order=ASC&showposts=5');
    		while ($future_events->have_posts()) : $future_events->the_post();
    		$do_not_duplicate = $post->ID;
    	?>
    
    	<li>
    		<span class="date">
    			<?php the_time('M. j | g:i a'); ?>
    		</span><br />
    		<a href="<?php the_permalink() ?>">
    			<?php// the_title(); ?>
    		</a>
    	</li>
    	<?php endwhile; ?><?php rewind_posts(); ?>
    </ul>

    Any thoughts/suggestions?

    Thanks!

  2. Ben B
    Member
    Posted 5 years ago #

    I'll chime in and say I would love to see an example of a bulletproof mini-loop. It's a really powerful way of accessing page information that's otherwise unavailable (the_excerpt, for example). I've tried a multitude of methods, but they produce some odd results.

    Does anyone think they have the perfect implementation?

    Ben

  3. mores
    Member
    Posted 5 years ago #

    Same here - everything that's listed in the codex concerning multiple loops doesn't work for me anymore.

    Well actually it does - sidebar etc. all works beautifully. But I'm running a mini-loop in the header area to list partner logos, and that breaks my site ever since I upgraded to 2.8.4

  4. dvsmith
    Member
    Posted 5 years ago #

    Oddly, this works fine on the front page, but not in the sidebar:

    <h2>Upcoming Events</h2>
    		<?php $posts = get_posts('category_name=Calendar&showposts=5&post_status=future&orderby=date&order=ASC'); ?>
    		<?php if( $posts ) : ?>
    		<ul>
    			<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    			<li>
    				<span class="date">
    					<?php the_time('D. F j, Y | g:i a'); ?>
    				</span><br />
    				<a href="<?php the_permalink() ?>">
    					<?php the_title(); ?>
    				</a>
    			</li>
    			<?php endforeach; ?>
    		</ul> 
    
    		<?php else : ?>
    			<ul>
    				<li type="none">
    					<p class="center">There are no events currently listed in the database. Check back soon for updates.</p>
    				</li>
    			</ul>
    		<?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic