Make WordPress Core

Ticket #23202: 23202.alt.patch

File 23202.alt.patch, 1.1 KB (added by wpsmith, 11 years ago)

Alternative solution

  • post-template.php

     
    12531253 * @uses $wp_query
    12541254 *
    12551255 * @param string $template The specific template name if specific matching is required.
     1256 * @param bool $loop Whether is_page_template() should be available in the loop.
    12561257 * @return bool True on success, false on failure.
    12571258 */
    1258 function is_page_template( $template = '' ) {
    1259         if ( ! is_page() )
     1259function is_page_template( $template = '', $loop = false ) {
     1260    // Bail if (1) not a page and not in the loop or (2) in loop and not available in loop
     1261        if ( ( ! is_page() && ! in_the_loop() ) || ( in_the_loop() && ! $loop ) )
    12601262                return false;
     1263   
     1264    if ( in_the_loop() ) {
     1265        global $wp_the_query;
     1266        $page_template = get_page_template_slug( $wp_the_query->queried_object_id );
     1267    } else {
     1268        $page_template = get_page_template_slug( get_queried_object_id() );
     1269    }
    12611270
    1262         $page_template = get_page_template_slug( get_queried_object_id() );
    1263 
    12641271        if ( empty( $template ) )
    12651272                return (bool) $page_template;
    12661273