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;
}

你可能感兴趣的:(php)