Make WordPress Core


Ignore:
Timestamp:
08/12/2008 08:18:05 PM (16 years ago)
Author:
westi
Message:

Refactor template location code to reduce duplication.
Also make it easier for theme authors to pull in seperate files into templates while making theme overrideable. See #7492.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/general-template.php

    r8600 r8624  
    55function get_header() {
    66    do_action( 'get_header' );
    7     if ( file_exists( STYLESHEETPATH . '/header.php') )
    8         load_template( STYLESHEETPATH . '/header.php');
    9     elseif ( file_exists( TEMPLATEPATH . '/header.php') )
    10         load_template( TEMPLATEPATH . '/header.php');
    11     else
     7    if ('' == locate_template(array('header.php'), true))
    128        load_template( get_theme_root() . '/default/header.php');
    139}
     
    1612function get_footer() {
    1713    do_action( 'get_footer' );
    18     if ( file_exists( STYLESHEETPATH . '/footer.php') )
    19         load_template( STYLESHEETPATH . '/footer.php');
    20     elseif ( file_exists( TEMPLATEPATH . '/footer.php') )
    21         load_template( TEMPLATEPATH . '/footer.php');
    22     else
     14    if ('' == locate_template(array('footer.php'), true))
    2315        load_template( get_theme_root() . '/default/footer.php');
    2416}
     
    2719function get_sidebar( $name = null ) {
    2820    do_action( 'get_sidebar' );
    29     if ( isset($name) && file_exists( STYLESHEETPATH . "/sidebar-{$name}.php") )
    30         load_template( STYLESHEETPATH . "/sidebar-{$name}.php");
    31     elseif ( isset($name) && file_exists( TEMPLATEPATH . "/sidebar-{$name}.php") )
    32         load_template( TEMPLATEPATH . "/sidebar-{$name}.php");
    33     elseif ( file_exists( STYLESHEETPATH . '/sidebar.php') )
    34         load_template( STYLESHEETPATH . '/sidebar.php');
    35     elseif ( file_exists( TEMPLATEPATH . '/sidebar.php') )
    36         load_template( TEMPLATEPATH . '/sidebar.php');
    37     else
     21   
     22    $templates = array();
     23    if ( isset($name) )
     24        $templates[] = "sidebar-{$name}.php";
     25   
     26    $templates[] = "sidebar.php";
     27   
     28    if ('' == locate_template($templates, true))
    3829        load_template( get_theme_root() . '/default/sidebar.php');
    3930}
Note: See TracChangeset for help on using the changeset viewer.