[wp-hackers] Regarding wp markup language
Otto
otto at ottodestruct.com
Mon Apr 19 21:52:56 UTC 2010
On Mon, Apr 19, 2010 at 9:30 AM, Jeremy Clarke <jer at simianuprising.com> wrote:
> For your consideration:
>
> function the_loop($args) {
> $defaults = array (
> ...
I'm not opposed to the idea, but it strikes me that a function call
with some customization type stuff in it is not really any clearer
than simply having the loop spelled out explicitly right there.
A wrapper is only useful when it simplifies. I don't think callback
functions are necessarily simpler by design. Especially when you have
people wanting to do things like style alternating posts differently,
or put advertising after the third post, etc.
Yes, you can probably make a function generic enough to do this sort
of thing, but I think you'd really be better off making the loop
simpler directly instead of trying to eliminate it entirely.
Your basic loop is this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
...
<?php endwhile; ?>
It could be a bit easier than this. And one could feasibly eliminate
the use of globals, which always make things so difficult.
Now, this is just me thinking out loud here... What if the Loop fed
into an object? That object could be like a container for your posts.
You could pass it a function to output those posts like a callback, or
you could get the posts from it one at a time and display them how you
wanted. You might be able to loop through it directly even.
The WP_Query actually covers some of this ground, the problem is the
main Loop functions all act on globals. Perhaps those could be built
into this object instead.
I could have a WP_Posts which extends the WP_Query object. I could say
$posts = new WP_Posts() to get the default query. WP_Posts could
implement Iterator (or IteratorAggregate), so then I could say
something like
foreach ($posts as $post) {
$post->the_title();
$post->the_content();
}
No globals, no fuss, no muss.
Now, this sort of thing is PHP 5 only. Still, if the implementation is
good, it might be the pushover point, eh?
-Otto
More information about the wp-hackers
mailing list