如果想给某个分类目录下的内容页用不的模板,可以使用以下的方式实现。

将以下这段代码放到functions.php中

add_filter( 'single_template', 'get_wordpress_cat_template' ) ;
function get_wodepress_cat_template( $single_template ) {
    global $post;//wodepress.com
    if ( is_category( 'news' ) || in_category( 'news' ) ) {
        $single_template = dirname( __FILE__ ) . '/single-news.php';
    }
    return $single_template;
}

上面的”news”可以是分别目录的别名,也可以是分类目录的ID。

将代码添加了保存后,在主题文件夹中新建single-news.php文件。此时别名为news的分类目录下的内容页调用的的就是single-news.php对应的模板了。