[wp-hackers] Two loops on one page?

Owen Winkler ringmaster at midnightcircus.com
Tue Nov 9 21:10:54 UTC 2004


Michael Heilemann wrote:
> How the devil do I have two loops on the same page?

I droped this code in the sidebar, and something similar for the main loop:

<?php
$query_string = 'cat=5&posts_per_page=3&what_to_show=posts';
$posts = query_posts($query_string);
?>
<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
<li><?php echo $post->post_content; ?>
<?php comments_popup_link(__('(0) &raquo;'), __('(1) &raquo;'), __('(%) 
&raquo;')); ?>
<?php edit_post_link('(e)'); ?></li>
<?php endforeach; else: ?>
<li><?php _e('Sorry, there are no active links at this time.'); ?></li>
<?php endif; ?>

Unfortunately, when you run query_posts, the category cache isn't 
cleared before it's rebuilt, and you get two categories attached to each 
post when it tries to list them.  Bug?  I don't know, because nobody 
could tell me if this was the way I was supposed to do this.

Owen




More information about the hackers mailing list