wordpress自定义文章分类

 //产品
function customer_taxonomy_product() {
    $post_taxonomy_type = 'porduct_category';
    $post_type = 'product';
    $labels = [
        'name'              => '产品分类',
        'singular_name'     => '产品分类',
        'search_items'      => '搜索产品分类',
        'all_items'         => '所有产品分类',
        'parent_item'       => '上级分类',
        'parent_item_colon' => '上级分类:',
        'edit_item'         => '编辑产品分类',
        'update_item'       => '更新产品分类',
        'add_new_item'      => '添加产品分类',
        'new_item_name'     => '新产品分类',
        'menu_name'         => '产品分类'
    ];
    customer_taxonomy_seeting( $post_taxonomy_type, $post_type, $labels );
}

//案例
function customer_taxonomy_case() {
    $post_taxonomy_type = 'case_category';
    $post_type = 'case';
    $labels = [
        'name'              => '案例分类',
        'singular_name'     => '案例分类',
        'search_items'      => '搜索案例分类',
        'all_items'         => '所有案例分类',
        'parent_item'       => '上级分类',
        'parent_item_colon' => '上级分类:',
        'edit_item'         => '编辑案例分类',
        'update_item'       => '更新案例分类',
        'add_new_item'      => '添加案例分类',
        'new_item_name'     => '新案例分类',
        'menu_name'         => '案例分类'
    ];
    customer_taxonomy_seeting( $post_taxonomy_type, $post_type, $labels );
}

add_action( 'init', 'customer_taxonomy_product', 0 );
add_action( 'init', 'customer_taxonomy_case', 0 );

 function customer_taxonomy_seeting( $post_taxonomy_type, $post_type, $labels ) {
    $labels_args = seeting_taxonomy_args( $labels );
    register_taxonomy( $post_taxonomy_type, $post_type, $labels_args );
 }

 function seeting_taxonomy_labels( $labels ) {
    $labels_arr = [
        'name'              => $labels['name'],
        'singular_name'     => $labels['singular_name'],
        'search_items'      => $labels['search_items'],
        'all_items'         => $labels['all_items'],
        'parent_item'       => $labels['parent_item'],
        'parent_item_colon' => $labels['parent_item_colon'],
        'edit_item'         => $labels['edit_item'],
        'update_item'       => $labels['update_item'],
        'add_new_item'      => $labels['add_new_item'],
        'new_item_name'     => $labels['new_item_name'],
        'menu_name'         => $labels['menu_name'],
    ];
    return $labels_arr;
 }

 function seeting_taxonomy_args( $labels ) {
    $args_arr = array(
        'labels' =>seeting_taxonomy_labels($labels),
        'hierarchical' => true,
    );
    return $args_arr;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值