[wp-hackers] Regarding wp markup language

Jeremy Clarke jer at simianuprising.com
Mon Apr 19 14:30:37 UTC 2010


For your consideration:

function the_loop($args) {
    $defaults = array (
           'query' => '', // Default uses current page query, this overrides
it with new WP_Query()
           'post_display_callback' => '', // Custom post display function,
overrides default.
           'loop_start_callback' => '', // Optional callback for start of
loop
           'loop_end_callback' => '', // Optional callback for end of loop
           'before' => '', // Show this before loop if there are posts
(easier than callback)
           'after' => '', // Show this after loop if there are posts (easier
than callback
    );
    $args = wp_parse_args($args, $defaults);
    extract($args, EXTR_SKIP);
    [...]
}

This would make it really easy to customize the loop by adding a callback to
functions.php for post display then calling it in your templates. Themers
could design several callbacks - one for headlines, one for avatars, one for
big photos to show in a slider - then use the_loop() in different parts of
the site by just altering the post_display_callback argument.

I particularly like the idea of making it very easy to get away from the
clusterfuck of get_posts(), query_posts() and new WP_Query(), which seems to
confuse all new users because they don't understand what the differences are
or what insane effects query_posts() will have on their sites (specifically
on is_*() functions that come after). In this model we could switch entirely
to the new WP_Query() way without forcing people to handle the query objects
themselves. It also works to just clear everyone's palate by abstracting
those particular functions into oblivion and replacing them most of the time
(though obviously they'd still be there for the hardcore!).

Another bonus is that this system would oust the_post() from most themes,
which to me is good because it does not make sense given the language of the
rest of the template tag system. the_* functions always echo out the denoted
thing, but the_post() just loads up global variables and stuff, which is not
at all what people would expect (IMHO if the_post() were consistent with the
rest of the API it would do what 'post_display_callback' does in my proposed
system, echo out a default version of the post contents).

-- 
Jeremy Clarke | http://jeremyclarke.org
Code and Design | http://globalvoicesonline.org


More information about the wp-hackers mailing list