例如,我们准备让 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使用哪种文章模板。
JA5A 正则表达式陈广佳版本(超详细)
Linux Lite 6.4今日发布基于 Ubuntu 22.04.2 LTS/原生应用支持 Zstd 压缩
0.1秒的价值!浅谈Web前端页面提速问题实用指南
Linux 6.3发布第4个候选版本 diffstat占比超过50%
linux无法识别ntfs格式U盘怎么办? 解决linux不识别nfst格式u盘问题技巧
Linux Mint 21.2 将于 6 月发布 主要改进了登录屏幕