[wp-hackers] Modular Themes: Apply the template hierarchy to folders within a theme

Daryl Koopersmith dkoopersmith at gmail.com
Tue Apr 6 17:31:01 UTC 2010


Hey everyone,

I've recently been working on a patch and several posts explaining how
modular themes can improve WP. For anyone who's seen my presentation from
WordCamp Ireland, this is the patch I spoke about.

By applying the template hierarchy to folders within a theme, theme
developers will be able to break themes into modules and substantially
reduce repeated code.

If you look at Twenty Ten, it uses get_template_part() to simulate parts of
the template hierarchy when loading the loop (e.g. it looks for
loop-archive.php, then loop.php, etc.). However, any theme developer that
wants to implement the template hierarchy while loading a template part must
do so manually—there is currently no automated option. There are several
downsides to a manual implementation, namely the lack of a naming convention
and the sheer impossibility of implementing the entire template hierarchy by
hand. This patch solves that problem.

In addition, modular themes have the potential to transform theme
organization by reducing repeated code and making theme files more readable.

Based on my tests, this patch should not affect performance.

Interested?
*  Trac ticket: http://core.trac.wordpress.org/ticket/12877
*  Why we should add modular themes: http://wp.me/pS0xt-1f
*  How they can transform theme organization: http://wp.me/pS0xt-30
*  Performance tests: http://wp.me/pS0xt-3O

Finally, the patch has the added benefit of creating an accurate global
$wp_template_hierarchy object (and a getter method), so any plugin/theme can
access the template hierarchy for $wp_query.

Let me know what you think.

Thanks,
Daryl


More information about the wp-hackers mailing list