WordPress分类怎么用不同的模板?试试Custom Category Templates

本文介绍了如何使用WordPress插件Custom Category Templates为每个分类设置独特模板,以及不借助插件的实现方式,只需将代码添加到functions.php中。
摘要由CSDN通过智能技术生成

WordPress插件Custom Category Templates 是一款简单轻量级插件,允许你为每个类别选择特定模板,就像页面模板一样。

安装方法:后台-插件-搜索:Custom Category Templates 安装并启用,在编辑分类时会添加一个选择模板的选项。

下面是不用安装插件的解决方法,可以直接添加到当前主题函数模板functions.php中即可。

// 分类选择模板
class Select_Category_Template{
public function __construct() {
add_filter( 'category_template', array($this,'get_custom_category_template' ));
add_action ( 'edit_category_form_fields', array($this,'category_template_meta_box'));
add_action( 'category_add_form_fields', array( &$this, 'category_template_meta_box') );
add_action( 'created_category', array( &$this, 'save_category_template' ));
add_action ( 'edited_category', array($this,'save_category_template'));
do_action('Custom_Category_Template_constructor',$this);
}

// 添加表单到分类编辑页面
public function category_template_meta_box( $tag ) {
$t_id = $tag->ter
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值