### [WordPress如何自定义文章详情页模板](https://www.prosaas.cn/article/8348) **Published:** 2019-07-19T08:39:21 **Author:** 5201314 **Excerpt:** 如果想让某个分类的文章页面样式有别于其它分类,我们可以使用自定义的模板的方法实现。例如,我们准备让名称为Wor… ![](//zhiqipro.oss-cn-beijing.aliyuncs.com/2023/12/20231212131115817.jpg) 如果想让某个分类的文章页面样式有别于其它分类,我们可以使用自定义的模板的方法实现。例如,我们准备让名称为WordPress的分类文章使用有别于其它分类的模板样式, 首先在所用主题根目录新建一个名称 single-wordpress.php的模板文件。将以下代码片段添加到您的当前主题的 functions.php 文件: add\_action('template\_include', 'load\_single\_template'); function load\_single\_template($template) { $new\_template = ''; // single post template if( is\_single() ) { global $post; // 'wordpress' is category slugs if( has\_term('wordpress', 'category', $post) ) { // use template file single-wordpress.php $new\_template = locate\_template(array('single-wordpress.php' )); } } return ('' != $new\_template) ? $new\_template : $template; } 上面的代码将指定WordPress分类的文章,使用 single-wordpress.php 模板文件。同理,你可以重复以上的步骤,让其它分类也可以使用自定义模板。 更多wordpress相关技术文章,请访问wordpress教程栏目进行学习! 以上就是WordPress如何自定义文章详情页模板的详细内容,更多请关注知企PROSAAS其它相关文章! **Categories:** WordPress ---