[wp-trac] [WordPress Trac] #12877: Modular themes: Apply template hierarchy to folders within a theme

WordPress Trac wp-trac at lists.automattic.com
Thu Dec 30 19:21:55 UTC 2010


#12877: Modular themes: Apply template hierarchy to folders within a theme
-----------------------------+-----------------------------
 Reporter:  koopersmith      |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Future Release
Component:  Themes           |     Version:  3.0
 Severity:  normal           |  Resolution:
 Keywords:  has-patch        |
-----------------------------+-----------------------------

Comment (by willnorris):

 One minor thing I added in my implementation was to include:
 `$template_namess[] = $module . '.php'` in `get_template_module()`, so
 that it behaves a little more similarly to `get_template_part()`.  Because
 of this, I also renamed `$folder` to `$module` since it isn't strictly
 looking in a folder.  So you end up with:

 {{{
 function get_template_module( $module ) {
     $template_hierarchy = get_template_hierarchy();
     $template_names = array();
     foreach( $template_hierarchy as $template_name ) {
         $template_names[] = $module . '/' . $template_name;
     }
     $template_names[] = $module . '.php';

      return locate_template($template_names, true);
 }
 }}}


 This also makes a secondary use case of get_template_module() a lot
 cleaner.  I break up my entry markup so that it is easier to override them
 in a child theme.  (see: https://github.com/willnorris/pdx-
 theme/blob/master/loop/index.php).  With this extra template name, I can
 simply have `entry/title.php` template files instead of needing
 `entry/title/index.php`.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12877#comment:26>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list