修好了!我现在创建了single
文件夹在我的主题的目录,并把特定类别的模板在那里。为了启用此功能,我将其添加到主题的函数文件中
/*
* 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;
}
这要感谢
this article!