Make WordPress Core

Ticket #12105: singular-template.diff

File singular-template.diff, 1.4 KB (added by greenshady, 15 years ago)
  • template-loader.php

     
    3636        } else if ( is_page() && $template = get_page_template() ) {
    3737                include($template);
    3838                return;
     39        } else if ( is_singular() && $template = get_page_template() ) {
     40                include( $template );
     41                return;
    3942        } else if ( is_category() && $template = get_category_template()) {
    4043                include($template);
    4144                return;
  • theme.php

     
    895895}
    896896
    897897/**
     898 * Retrieve the path of the singular template in current or parent template.
     899 *
     900 * @since 0.3
     901 *
     902 * @return string
     903 */
     904function get_singular_template() {
     905        global $wp_query;
     906
     907        $id = (int) $wp_query->post->ID;
     908
     909        $templates = array();
     910        $templates[] = "{$wp_query->post->post_type}-{$wp_query->post->post_name}.php";
     911        $templates[] = "{$wp_query->post->post_type}-{$id}.php";
     912        $templates[] = "{$wp_query->post->post_type}.php";
     913        $templates[] = "singular.php";
     914
     915        return apply_filters( 'singular_template', locate_template( $templates ) );
     916}
     917
     918/**
    898919 * Retrieve path of attachment template in current or parent template.
    899920 *
    900921 * The attachment path first checks if the first part of the mime type exists.