[wp-hackers] Needed: More Elegant Solution for Using another "the loop"

Tor Bjornrud bjornrud at msu.edu
Sun Oct 10 20:32:06 UTC 2004


On Oct 10, 2004, at 3:36 PM, Mark Shields wrote:
> <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
> <?php
> $postcount += 1;
> if ($postcount == 1) {
> 	get_breadcrumb(0, 1, 1, 1);
> 	if ($showRoot || $m || $author || $s || $cat) {
> 		echo "<br />";
> 	}
> }
> ?>
> <?php endforeach; else: ?>
> <?php endif; ?>
>
[[snip]]
> I'd like a more elegant block of code (re: easier/smaller to put it
> the index.php file) than that.

I don't know about more elegant, as that's all in the eye of the 
beholder, but this is smaller.  Sorry if this isn't what you're looking 
for.  It assumes three things:

1. That the breaking in and out of php isn't needed and you don't care 
about needing those newlines in your html.

2. That postcount was intialized to 0 somewhere else above the script.

3. That the keys to $posts are the default keys of an array (0, 1, 2, 3)

<?php if ($posts) : foreach ($posts as $ct=>$post) : start_wp();
if (!$ct){
	get_breadcrumb(0, 1, 1, 1);
	if ($showRoot || $m || $author || $s || $cat) { echo '<br />'; }	
}
endforeach; else:
endif; ?>




More information about the hackers mailing list