• 首页
  • WordPress下载
  • WordPress教程
  • 酱茄Free主题
  • WordPress小程序
    • 酱茄Pro小程序(社区+商城)
    • 酱茄Cms小程序(积分阅读)
    • 酱茄Free小程序(免费下载)
  • 首页
  • WordPress下载
  • WordPress教程
  • 酱茄Free主题
  • WordPress小程序
    • 酱茄Pro小程序(社区+商城)
    • 酱茄Cms小程序(积分阅读)
    • 酱茄Free小程序(免费下载)

WordPress分类怎么用不同的模板 插件Custom Category Templates

2020-10-13
in WordPress教程
0

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


安装方法1:

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


安装方法2:

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

// zhuige.com添加表单到分类编辑页面
public function category_template_meta_box( $tag ) {
$t_id = $tag->term_id;
$cat_meta = get_option( "category_templates");
$template = isset($cat_meta[$t_id]) ? $cat_meta[$t_id] : false;
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="cat_Image_url"><?php _e('Category Template'); ?></label></th>
<td>
<select name="cat_template" id="cat_template">
<option value='default'><?php _e('Default Template'); ?></option>
<?php page_template_dropdown($template); ?>
</select>
<br />
<span class="description"><?php _e('为此分类选择一个模板'); ?></span>
</td>
</tr>
<?php
do_action('Custom_Category_Template_ADD_FIELDS',$tag);
}
 
// zhuige.com保存表单
public function save_category_template( $term_id ) {
if ( isset( $_POST['cat_template'] )) {
$cat_meta = get_option( "category_templates");
$cat_meta[$term_id] = $_POST['cat_template'];
update_option( "category_templates", $cat_meta );
do_action('Custom_Category_Template_SAVE_FIELDS',$term_id);
}
}

// zhuige.com分类选择模板
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);
}
 
// zhuige.com处理选择的分类模板
function get_custom_category_template( $category_template ) {
$cat_ID = absint( get_query_var('cat') );
$cat_meta = get_option('category_templates');
if (isset($cat_meta[$cat_ID]) && $cat_meta[$cat_ID] != 'default' ){
$temp = locate_template($cat_meta[$cat_ID]);
if (!empty($temp))
return apply_filters("Custom_Category_Template_found",$temp);
}
return $category_template;
}
}
 
$cat_template = new Select_Category_Template();

 

Tags: WordPressWordPress主题WordPress插件WordPress模板
Previous Post

WordPress登录页面美化插件:Login Designer

Next Post

WordPress网站标题中的&#8211怎么转换成分隔符

Please login to join discussion

酱茄Pro小程序

热门标签

Elementor Login Designer nofollow是什么 Pure-Highlightjs Safe SVG TinyPNG Twenty Twenty One woocommerce WooCommerce商城 WordPress WordPress 5.6 WordPress 5.6下载 WordPress下载 WordPress主题 WordPress仪表盘 WordPress函数 WordPress官网 WordPress小程序 WordPress建站 WordPress忘记密码 WordPress插件 WordPress教程 WordPress模板 WP Admin Cache WP Dark Mode WP Mail SMTP WP Term Order 什么是SVG 代码高亮 区块编辑器 古腾堡 小程序 小程序源码 标签 知识付费小程序 追格 酱茄 酱茄cms 酱茄Free 酱茄Free主题 酱茄Free小程序 酱茄Pro 酱茄主题 酱茄小程序 酱茄小程序开源版

广告推荐

酱茄Cms小程序

  • 关于/联系
  • 免责声明
  • 用户协议
  • 隐私政策
  • 网站地图
  • Feed

Copyright © 2021 追格 京ICP备16067668号 京公网安备 11010802022707号

No Result
View All Result
  • 首页
  • WordPress下载
  • WordPress教程
  • 酱茄Free主题
  • WordPress小程序
    • 酱茄Pro小程序(社区+商城)
    • 酱茄Cms小程序(积分阅读)
    • 酱茄Free小程序(免费下载)

Copyright © 2021 追格 京ICP备16067668号 京公网安备 11010802022707号

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In