Changeset 6228

Show
Ignore:
Timestamp:
10/12/07 20:01:16 (9 months ago)
Author:
westi
Message:

Add is_page_template() function to allow theme developers to detect that they are is a page template. Fixes #3335

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-includes/post-template.php

    r6201 r6228  
    493493} 
    494494 
     495/** 
     496 * is_page_template() - Determine wether or not we are in a page template 
     497 * 
     498 * This template tag allows you to determine wether or not you are in a page template. 
     499 * You can optional provide a template name and then the check will be specific to 
     500 * that template. 
     501 * 
     502 * @package Template Tags 
     503 * @global object $wp_query 
     504 * @param string $template The specific template name if specific matching is required 
     505 */ 
     506function is_page_template($template = '') { 
     507    if (!is_page()) { 
     508        return false; 
     509    } 
     510 
     511    global $wp_query; 
     512 
     513    $page = $wp_query->get_queried_object(); 
     514    $custom_fields = get_post_custom_values('_wp_page_template',$page->ID); 
     515    $page_template = $custom_fields[0]; 
     516 
     517    // We have no argument passed so just see if a page_template has been specified 
     518    if ( empty( $template ) ) { 
     519        if (!empty( $page_template ) ) { 
     520            return true; 
     521        } 
     522    } elseif ( $template == $page_template) { 
     523        return true; 
     524    } 
     525 
     526    return false; 
     527} 
     528 
    495529?>