[wp-hackers] The loop, old and new way - which one is better?
Mark Shields
laebshade at gmail.com
Sat Feb 19 17:04:48 GMT 2005
Way back when, between the current version and 1.2, the loop was
something like this:
<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
<?php endforeach; else: ?>
<?php endif; ?>
It changed to:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Several questions.
Why the change?
Which is better?
I have a plugin (Breadcrumb Navigation) that used a modified version
(thanks to Mark Jaquith and Tor Bjornrud for help with that!) of the
first loop.
<?php if ($posts) : foreach ($posts as $ct=>$post) : start_wp();
if (!$ct){
}
endforeach; else:
endif;
?>
To get the plugin to work properly so it can make use of $post and all
the variables/functions that work after start_wp(); is run. Here's
the million dollar question: how can I use the new loop to work?
Someone made mention of the rewind_posts(); function. I attempted to
use this and failed.
If you're not familiar with the plugin, it's designed to do several
things, but mainly:
When $single is set, display a "home" link, categories in a post, and
the post name.
When $cat is set, display a "home" link, and the current category viewing
And so forth for pretty much each different type of page.
--
- Mark Shields
More information about the hackers
mailing list