最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
WordPress不同分类的文章使用不同模板的例子
时间:2022-06-25 18:38:53 编辑:袖梨 来源:一聚教程网
例如,我们准备让 xinwen 的分类文章使用有别于其它分类的文章模板样式:
1、在所用主题根目录新建一个名称 single-xinwen.php的模板文件。
2、将以下代码片段添加到您的当前主题的 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;
}
3、重复以上的步骤,让其它分类也可以使用自定义模板。
4、扩展:在后台设置选项里text输入框,自定义哪些栏目ID使用哪种文章模板。
相关文章
- 心动小镇10.9溜溜橡木与无瑕萤石位置 10-18
- 爱江山更爱美人最新兑换码分享 10-18
- 伊瑟多乐丝技能加点及搭配推荐 10-18
- 永远的蔚蓝星球合作模式词条获取方法 10-18
- 益城月下聚同好,“游戏+非遗”共潮生 —— 益世界 2025 CICF×AGF 展台燃动国庆 10-18
- 王于兴师项羽虞姬队玩法搭配分享 10-18