[ create a new paste ] login | about

Link: http://codepad.org/0YxmWSpY    [ raw code | output | fork ]

PHP, pasted on Aug 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function get_custom_single_template($single_template) {
     global $post;

     $terms = get_the_terms( $post->ID, 'products_type' );
     $terms_slug = $terms[0]->slug;
     $post_type = get_post_type( $post->ID );

     $single_template = dirname( __FILE__ ) . '/single-' . $post_type . '-' . $terms_slug . '.php';

     if ( !file_exists( $single_template ) ) {
     	$single_template = dirname( __FILE__ ) . '/single.php';
     }

     return $single_template;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function get_custom_single_template($single_template) {
     global $post;

     $terms = get_the_terms( $post->ID, 'products_type' );
     $terms_slug = $terms[0]->slug;
     $post_type = get_post_type( $post->ID );

     $single_template = dirname( __FILE__ ) . '/single-' . $post_type . '-' . $terms_slug . '.php';

     if ( !file_exists( $single_template ) ) {
     	$single_template = dirname( __FILE__ ) . '/single.php';
     }

     return $single_template;
}


Create a new paste based on this one


Comments: