[wp-trac] [WordPress Trac] #23142: Make it possible to "stem" an arbitrary prefix with the Template Hierarchy's "stemming" logic.

WordPress Trac noreply at wordpress.org
Tue Jan 8 13:04:03 UTC 2013


#23142: Make it possible to "stem" an arbitrary prefix with the Template
Hierarchy's "stemming" logic.
-----------------------------+-----------------------------
 Reporter:  rulatir          |       Type:  feature request
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Themes
  Version:  3.5              |   Severity:  normal
 Keywords:                   |
-----------------------------+-----------------------------
 Please expose the template hierarchy "stemming" logic for theme
 developers. By "stemming" I mean the process by which the list of
 candidate template filenames  (e.g. page-meaningoflife.php, page-42.php,
 page.php) is generated.

 I '''know''' that the way template-loader.php is currently written, such
 list is never explicitly assembled. I consider this a deficiency. The
 "stemming" logic should be available as an API:


 {{{
 function wp_template_candidates($prefix="") {

     $filenames = array();

     // Extensively refactored code from template-loader.php and
 template.php

     return $filenames;
 }
 }}}

 The new template-loader.php could then probably be just reduced almost to
 this:

 {{{
 locate_template(wp_template_candidates(),true);
 }}}

 But the real motivation is to be able to use a single layout template that
 includes different versions of "parts" like menu or sidebars depending on
 the query type and queried object, exactly as the template hierarchy does.
 This can of course be done with ad-hoc checks:

 {{{

 if (is_home()) { locate_template("home/sidebar.php", true); }

 }}}

 but making this consistent with how template hierarchy works would involve
 basically reimplementing much of it. The proposed API would make it
 possible to override parts of a template for specific query types or
 queried objects just by creating an appropriately located and named file,
 and without modifying the main layout file:

 {{{

 /*
  *   File: MyTheme/includes/body-layout.php
  */

 <div id="main-menu">
 <?php locate_template(wp_template_candidates("main-menu/"),true); ?>
 </div>

 <?php

 //On a "video" category page, this will pick MyTheme/social_slider
 /category-video.php

 @include_once locate_template(wp_template_candidates("social_slider/"));

 ?>

 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23142>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list