如果想让某个分类的文章页面样式有别于其它分类,我们可以使用自定义的模板的方法实现。例如,我们准备让名称为wordpress的分类文章使用有别于其它分类的模板样式,
首先在所用主题根目录新建一个名称single-wordpress.php的模板文件。将以下代码片段添加到您的当前主题的functions.php文件:
add_action('template_include','load_single_template');functionload_single_template($template){$new_template='';//singleposttemplateif(is_single()){global$post;//'wordpress'iscategoryslugsif(has_term('wordpress','category',$post)){//usetemplatefilesingle-wordpress.php$new_template=locate_template(array('single-wordpress.php'));}}return(''!=$new_template)?$new_template:$template;}