WordPress.org

Make WordPress Core

Ticket #12105: singular_template_post_types.diff

File singular_template_post_types.diff, 1.1 KB (added by ptahdunbar, 8 years ago)

singular_template_post_types

  • wp-includes/theme.php

     
    897897
    898898/**
    899899 * Retrieve path of single template in current or parent template.
     900 *
     901 * Will first look for singular-{post_type}-{slug}.php
     902 * The will search for 'singular-{post_type}-{id}.php' followed by 'singular-{post_type}.php',
     903 * and finally 'singular.php'
    900904 *
    901905 * @since 1.5.0
    902906 *
    903907 * @return string
    904908 */
    905909function get_single_template() {
    906         return get_query_template('single');
     910        global $wp_query;
     911       
     912        $id = (int) $wp_query->post->ID;
     913       
     914        $templates = array();
     915        $templates[] = "singular-{$wp_query->post->post_type}-{$wp_query->post->post_name}.php";
     916        $templates[] = "singular-{$wp_query->post->post_type}-{$id}.php";
     917        $templates[] = "singular-{$wp_query->post->post_type}.php";
     918        $templates[] = "singular.php";
     919        $templates[] = "single.php"; // Deprecated, use singular.php instead
     920       
     921        return apply_filters('single_template', locate_template($templates));
    907922}
    908923
    909924/**