Load a template part into a template
Makes it easy for a theme to reuse sections of code in a easy to overload way for child themes.
Includes the named template part for a theme or if a name is specified then a specialised part will be included. 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.
For the $name parameter, if the file is called “{slug}-special.php” then specify “special”.
Signature
get_template_part( $slug, $name = null )
- slug
- (string) The slug name for the generic template.
- name
- (string) The name of the specialised template.
Default:null
Return
(void)
Source
function get_template_part( $slug, $name = null ) {
do_action( "get_template_part_{$slug}", $slug, $name );
$templates = array();
if ( isset($name) )
$templates[] = "{$slug}-{$name}.php";
$templates[] = "{$slug}.php";
locate_template($templates, true, false);
}
WP Trac GitHub Bitbucket
Link here
-
URL
http://queryposts.com/function/get_template_part/ -
HTML
<a href='http://queryposts.com/function/get_template_part/'>get_template_part()</a> -
Markdown
[get_template_part()](http://queryposts.com/function/get_template_part/) -
BBCode
[url=http://queryposts.com/function/get_template_part/]get_template_part()[/url]