Created
May 22, 2012 14:29
-
-
Save mikeemoo/2769411 to your computer and use it in GitHub Desktop.
Wordpress template loading
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
function get_header( $name = null ) { | |
do_action( 'get_header', $name ); | |
$templates = array(); | |
if ( isset($name) ) | |
$templates[] = "header-{$name}.php"; | |
$templates[] = 'header.php'; | |
// Backward compat code will be removed in a future release | |
if ('' == locate_template($templates, true)) | |
load_template( ABSPATH . WPINC . '/theme-compat/header.php'); | |
} | |
function locate_template($template_names, $load = false, $require_once = true ) { | |
$located = ''; | |
foreach ( (array) $template_names as $template_name ) { | |
if ( !$template_name ) | |
continue; | |
if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { | |
$located = STYLESHEETPATH . '/' . $template_name; | |
break; | |
} else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) { | |
$located = TEMPLATEPATH . '/' . $template_name; | |
break; | |
} | |
} | |
if ( $load && '' != $located ) | |
load_template( $located, $require_once ); | |
return $located; | |
} | |
function load_template( $_template_file, $require_once = true ) { | |
global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; | |
if ( is_array( $wp_query->query_vars ) ) | |
extract( $wp_query->query_vars, EXTR_SKIP ); | |
if ( $require_once ) | |
require_once( $_template_file ); | |
else | |
require( $_template_file ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment