您可以检查您的post-type-single-{post-type}。php首先尝试以下操作:
/* 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 post type */
if ($post->post_type == "POST TYPE NAME"){
if(file_exists(SINGLE_PATH . \'/single-\' . $post->post_type . \'.php\'))
return SINGLE_PATH . \'/single-\' . $post->post_type . \'.php\';
}
/* 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;
}
只需将“POST TYPE NAME”替换为自定义的POST TYPE NAME即可。