
如果想让某个分类的文章页面样式有别于其它分类,我们可以使用自定义的模板的方法实现。例如,我们准备让名称为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 模板文件。同理,你可以重复以上的步骤,让其它分类也可以使用自定义模板。
CWMS 2.0功能介绍:一、 员工考勤系统,国内首创CWMS2.0的企业员工在线考勤系统。二、 自定义URL Rewrite重写,友好的搜索引擎 URL优化。三、 代码与模板分离技术,支持超过5种类型的模板类型。包括:文章、图文、产品、单页、留言板。四、 购物车功能,CWMS2.0集成国内主流支付接口。如:淘宝、易趣、快钱等。完全可媲美专业网上商城系统。五、 多语言自动切换 中英文的说明。六、
0
更多wordpress相关技术文章,请访问wordpress教程栏目进行学习!
以上就是WordPress如何自定义文章详情页模板的详细内容,更多请关注php中文网其它相关文章!
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号