iamcanadian1973
10/19/2017 - 4:55 PM

general-template.php

<?php

/**
 * 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".
 *
 *
 * @param string      $slug The slug name for the generic template.
 * @param null|string $name
 * @param array       $data optional array of vars to inject into the template part
 * @param boolean     $return Whether to return or output the template
 */
function _s_get_template_part( $slug, $name = null, $data = array(), $return = false ) {
    
    do_action( "get_template_part_{$slug}", $slug, $name );
     
    $name = (string) $name;
    if ( '' !== $name )
	$templates[] = "{$slug}-{$name}.php";

    $templates[] = "{$slug}.php";
    
    if( is_array( $data ) ) {
        extract( $data );
    }
    
    // Return instead of echo
    if( $return ) {
        
        ob_start();
        include( locate_template( $templates ) );
        $content = ob_get_contents();
        ob_end_clean();
        
        return $content;
    }
    
    include( locate_template( $templates ) );
    
}