426 $id = get_queried_object_id(); |
426 $id = get_queried_object_id(); |
427 $template = get_page_template_slug(); |
427 $template = get_page_template_slug(); |
428 $pagename = get_query_var( 'pagename' ); |
428 $pagename = get_query_var( 'pagename' ); |
429 |
429 |
430 if ( ! $pagename && $id ) { |
430 if ( ! $pagename && $id ) { |
431 // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object |
431 // If a static page is set as the front page, $pagename will not be set. |
|
432 // Retrieve it from the queried object. |
432 $post = get_queried_object(); |
433 $post = get_queried_object(); |
433 if ( $post ) { |
434 if ( $post ) { |
434 $pagename = $post->post_name; |
435 $pagename = $post->post_name; |
435 } |
436 } |
436 } |
437 } |
641 * |
642 * |
642 * Searches in the STYLESHEETPATH before TEMPLATEPATH and wp-includes/theme-compat |
643 * Searches in the STYLESHEETPATH before TEMPLATEPATH and wp-includes/theme-compat |
643 * so that themes which inherit from a parent theme can just overload one file. |
644 * so that themes which inherit from a parent theme can just overload one file. |
644 * |
645 * |
645 * @since 2.7.0 |
646 * @since 2.7.0 |
|
647 * @since 5.5.0 The `$args` parameter was added. |
646 * |
648 * |
647 * @param string|array $template_names Template file(s) to search for, in order. |
649 * @param string|array $template_names Template file(s) to search for, in order. |
648 * @param bool $load If true the template file will be loaded if it is found. |
650 * @param bool $load If true the template file will be loaded if it is found. |
649 * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. |
651 * @param bool $require_once Whether to require_once or require. Has no effect if `$load` is false. |
|
652 * Default true. |
|
653 * @param array $args Optional. Additional arguments passed to the template. |
|
654 * Default empty array. |
650 * @return string The template filename if one is located. |
655 * @return string The template filename if one is located. |
651 */ |
656 */ |
652 function locate_template( $template_names, $load = false, $require_once = true ) { |
657 function locate_template( $template_names, $load = false, $require_once = true, $args = array() ) { |
653 $located = ''; |
658 $located = ''; |
654 foreach ( (array) $template_names as $template_name ) { |
659 foreach ( (array) $template_names as $template_name ) { |
655 if ( ! $template_name ) { |
660 if ( ! $template_name ) { |
656 continue; |
661 continue; |
657 } |
662 } |
680 * The globals are set up for the template file to ensure that the WordPress |
685 * The globals are set up for the template file to ensure that the WordPress |
681 * environment is available from within the function. The query variables are |
686 * environment is available from within the function. The query variables are |
682 * also available. |
687 * also available. |
683 * |
688 * |
684 * @since 1.5.0 |
689 * @since 1.5.0 |
|
690 * @since 5.5.0 The `$args` parameter was added. |
685 * |
691 * |
686 * @global array $posts |
692 * @global array $posts |
687 * @global WP_Post $post |
693 * @global WP_Post $post Global post object. |
688 * @global bool $wp_did_header |
694 * @global bool $wp_did_header |
689 * @global WP_Query $wp_query |
695 * @global WP_Query $wp_query WordPress Query object. |
690 * @global WP_Rewrite $wp_rewrite |
696 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
691 * @global wpdb $wpdb |
697 * @global wpdb $wpdb WordPress database abstraction object. |
692 * @global string $wp_version |
698 * @global string $wp_version |
693 * @global WP $wp |
699 * @global WP $wp Current WordPress environment instance. |
694 * @global int $id |
700 * @global int $id |
695 * @global WP_Comment $comment |
701 * @global WP_Comment $comment Global comment object. |
696 * @global int $user_ID |
702 * @global int $user_ID |
697 * |
703 * |
698 * @param string $_template_file Path to template file. |
704 * @param string $_template_file Path to template file. |
699 * @param bool $require_once Whether to require_once or require. Default true. |
705 * @param bool $require_once Whether to require_once or require. Default true. |
700 */ |
706 * @param array $args Optional. Additional arguments passed to the template. |
701 function load_template( $_template_file, $require_once = true ) { |
707 * Default empty array. |
|
708 */ |
|
709 function load_template( $_template_file, $require_once = true, $args = array() ) { |
702 global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; |
710 global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; |
703 |
711 |
704 if ( is_array( $wp_query->query_vars ) ) { |
712 if ( is_array( $wp_query->query_vars ) ) { |
705 /* |
713 /* |
706 * This use of extract() cannot be removed. There are many possible ways that |
714 * This use of extract() cannot be removed. There are many possible ways that |