I've used Justin Tadlock's great function for category specific custom post templates many times, where you can use single-cat-id.php for single posts belonging to a specific category. I just ran into a problem though working on a new site that needs to use the single-{posttype} template for a custom post type. The function seems to prevent the custom posts from using single-{posttype} template.
Here's the applicable code:
/* Define a constant path to our single template folder */
define(SINGLE_PATH, TEMPLATEPATH . '/single');
/* Filter the single_template with our custom function*/
add_filter('single_template', 'my_single_template');
/* Single template function which will choose our template*/
function my_single_template($single) {
global $wp_query, $post;
/* Checks for single template by category. Check by category slug and ID */
foreach((array)get_the_category() as $cat) :
if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php';
elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php';
endforeach;
/*Checks for default single post files within the single folder */
if(file_exists(SINGLE_PATH . '/single.php'))
return SINGLE_PATH . '/single.php';
elseif(file_exists(SINGLE_PATH . '/default.php'))
return SINGLE_PATH . '/default.php';
return $single; }
Any thoughts on how to modify the following code to allow both the original function of single-cat-id as well as single-{posttype}?