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

Daryl Koopersmith dkoopersmith at gmail.com
Wed Apr 7 06:02:50 UTC 2010


1) It's not really a "theme framework", but a small, powerful function. Yes,
it's possible to emulate this function via judicious including. I could also
implement the function in a plugin/theme by renaming and replicating several
hundred lines of WP code, but that isn't exactly practical (if one filter
were added to core, that would drop to several dozen, but I digress). The
patch relies heavily on core, and is designed to be a part of core. I
believe this function will be useful to all themes; a tool in a developer's
toolbox rather than a blueprint.

2) Modular themes increase the flexibility of child themes. When the
template hierarchy is applied, it checks for files in the child theme before
checking the parent theme. Since each module searches for files on all
levels of the template hierarchy, child themes have a greater opportunity to
override parent themes, and can pinpoint exactly where in the template
hierarchy they want to override the parent theme without the use of template
conditionals (i.e. is_category() ).

In addition, modules establish a naming convention (via the template
hierarchy), so developers will know exactly which filenames they can use to
override code (whereas get_template_part requires the user to inspect the
parent theme's code).

On Wed, Apr 7, 2010 at 12:26 AM, Stephen Rider <wp-hackers at striderweb.com>wrote:

> Two things --
>
> 1) If you want a "theme framework" of common code, it seems you could
> emulate this now wuth judicious include()ing of files within whatever
> hierarchy of folders you like.
>
> 2) How would this affect child themes?
>
> Stephen
>
>
> On Apr 6, 2010, at 12:31 PM, Daryl Koopersmith wrote:
>
> > 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
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list