[wp-trac] [WordPress Trac] #12105: Add support to get_single_template() for custom content types

WordPress Trac wp-trac at lists.automattic.com
Mon Feb 1 00:17:50 UTC 2010


#12105: Add support to get_single_template() for custom content types
-------------------------+--------------------------------------------------
 Reporter:  ptahdunbar   |       Owner:     
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  3.0
Component:  Template     |     Version:  3.0
 Severity:  normal       |    Keywords:     
-------------------------+--------------------------------------------------

Comment(by greenshady):

 I propose that we leave the single template alone because that's directly
 related to the "post" post type.  I'd love to see an alternate check for
 `get_singular_template()` after `is_attachment()`, `is_single()`, and
 `is_page()`.

 I don't believe `is_single()` should be true for anything but posts, but
 `is_singular()` should be true for all post types on singular views.

 This should provide the functionality for a new singular template but also
 preserve backwards compatiblity with the old templating system for
 `template-loader.php`:


 {{{
 } else if ( is_attachment() && $template = get_attachment_template() ) {
         remove_filter('the_content', 'prepend_attachment');
         include($template);
         return;
 } else if ( is_single() && $template = get_single_template() ) {
         include($template);
         return;
 } else if ( is_page() && $template = get_page_template() ) {
         include($template);
         return;

 /* New code. */
 } else if ( is_singular() && $template = get_singular_template() ) {
         include( $template );
         return;
 }}}


 New `get_singular_template()` function:


 {{{
 function get_singular_template() {
         global $wp_query;

         $id = (int) $wp_query->post->ID;

         $templates = array();
         $templates[] =
 "{$wp_query->post->post_type}-{$wp_query->post->post_name}.php";
         $templates[] = "{$wp_query->post->post_type}-{$id}.php";
         $templates[] = "{$wp_query->post->post_type}.php";
         $templates[] = "singular.php";

         return apply_filters( 'singular_template', locate_template(
 $templates ) );
 }
 }}}


 I removed `singular-` from the beginning so this would match how pages are
 currently done.  But, either way is fine with me.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12105#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list