Created
October 28, 2011 16:25
-
-
Save mattwiebe/1322689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Load a template part into a template. | |
* A subdirecory-favoring variant of get_template_part() for cleaner themes. | |
* | |
* Makes it easy for a theme to reuse sections of code in a easy to overload way | |
* for child themes. | |
* | |
* Includes {slug}/{slug}.php for a theme or if a name is specified then a | |
* specialised part will be included following the {slug}/{name}.php pattern. | |
* If the theme contains no {slug}.php file then no template will be included. | |
* | |
* The template is included using require, not require_once, so you may include the | |
* same template part multiple times. | |
* | |
* @author Matt Wiebe | |
* @link http://somadesign.ca/ | |
* @copyright 2011 | |
* @license GPLv2 | |
* | |
* @uses locate_template() | |
* @uses do_action() Calls 'get_template_smart_{$slug}' action. | |
* | |
* @param string $slug The slug name for the generic template. | |
* @param string $name The name of the specialised template. | |
*/ | |
function get_template_smart( $slug, $name = null ) { | |
do_action( "get_template_smart_{$slug}", $slug, $name ); | |
$templates = array(); | |
if ( isset($name) && ! empty($name) ) | |
$templates[] = "{$slug}/{$name}.php"; | |
$templates[] = "{$slug}/{$slug}.php"; | |
return locate_template($templates, true, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment