diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 284f95320..bdd9018f3 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -103,6 +103,9 @@ function get_sidebar( $name = null ) { * 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 parameter, if the file is called "{slug}-special.php" then specify * "special". * @@ -122,7 +125,7 @@ function get_template_part( $slug, $name = null ) { $templates[] = "{$slug}.php"; - locate_template($templates, true); + locate_template($templates, true, false); } /** diff --git a/wp-includes/theme.php b/wp-includes/theme.php index a34d4433b..74ff7cc9c 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -986,9 +986,10 @@ function get_comments_popup_template() { * * @param array $template_names Array of template files to search for in priority order. * @param bool $load If true the template file will be loaded if it is found. + * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. * @return string The template filename if one is located. */ -function locate_template($template_names, $load = false) { +function locate_template($template_names, $load = false, $require_once = true ) { if ( !is_array($template_names) ) return ''; @@ -1004,13 +1005,13 @@ function locate_template($template_names, $load = false) { } if ( $load && '' != $located ) - load_template($located); + load_template( $located, $require_once ); return $located; } /** - * Require once the template file with WordPress environment. + * Require the template file with WordPress environment. * * The globals are set up for the template file to ensure that the WordPress * environment is available from within the function. The query variables are @@ -1019,14 +1020,18 @@ function locate_template($template_names, $load = false) { * @since 1.5.0 * * @param string $_template_file Path to template file. + * @param bool $require_once Whether to require_once or require. Default true. */ -function load_template($_template_file) { +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 ( is_array( $wp_query->query_vars ) ) + extract( $wp_query->query_vars, EXTR_SKIP ); - require_once($_template_file); + if ( $require_once ) + require_once( $_template_file ); + else + require( $_template_file ); } /**