自定义邮件类型的自定义分类层次结构(例如类别和子类别)

时间:2011-04-27 作者:ItsPronounced

我正在为我创建的自定义帖子类型构建一些自定义分类法。

自定义帖子类型为Products. 对于自定义帖子类型Products 我创建了Category. 现在处于Category, 我想对Sub_Category. 我已经创建了所有分类法并将它们设置为层次结构,但是Sub_Category 税收似乎与Product 自定义帖子类型,而不是Category 自定义分类法。有没有办法做到这一点?我看到一个屏幕截图,有人在为他们创建的分类法填写分类表,它有一个家长选项,但我从来没有看到过。如何选择家长Category 我的分类SubCategory 分类学

这是我的CategorySubCategory 分类代码:

function create_productcategory_taxonomy() {
    $labels = array(
        \'name\' => _x( \'Categories\', \'taxonomy general name\' ),
        \'singular_name\' =>_x( \'Category\', \'taxonomy singular name\' ),
        \'search_items\' =>  __( \'Search Categories\' ),
        \'popular_items\' => __( \'Popular Categories\' ),
        \'all_items\' => __( \'All Categories\' ),
        \'parent_item\' => null,
        \'parent_item_colon\' => null,
        \'edit_item\' => __( \'Edit Product Category\' ),
        \'update_item\' => __( \'Update Product Category\' ),
        \'add_new_item\' => __( \'Add New Product Category\' ),
        \'new_item_name\' => __( \'New Product Category\' ),
        \'separate_items_with_commas\' => __( \'Separate categories with commas\' ),
        \'add_or_remove_items\' => __( \'Add or remove product categories\' ),
        \'choose_from_most_used\' => __( \'Choose from the most used categories\' )
        );

    register_taxonomy(\'tf_productcategory\', \'tf_products\', array (
        \'label\' => __(\'Product Category\'),
        \'labels\' => $labels,
        \'hierarchial\' => true,
        \'show_ui\' => true,
        \'query_var\' => true,
        \'rewrite\' => array( \'slug\' => \'product-category\'),
        )); 
}

function create_product_subcategory_taxonomy() {
    $labels = array(
        \'name\' => _x( \'SubCategories\', \'taxonomy general name\' ),
        \'singular_name\' =>_x( \'SubCategory\', \'taxonomy singular name\' ),
        \'search_items\' =>  __( \'Search SubCategories\' ),
        \'popular_items\' => __( \'Popular SubCategories\' ),
        \'all_items\' => __( \'All SubCategories\' ),
        \'parent_item\' => __( \'Main Category\' ),
        \'parent_item_colon\' => ( \'Main Category:\' ),
        \'edit_item\' => __( \'Edit Product SubCategory\' ),
        \'update_item\' => __( \'Update Product SubCategory\' ),
        \'add_new_item\' => __( \'Add New Product SubCategory\' ),
        \'new_item_name\' => __( \'New Product SubCategory\' ),
        \'menu_name\' => __( \'SubCategories\' )
        );

    register_taxonomy(\'tf_productsubcategory\', \'tf_products\', array (
        \'label\' => __(\'Product SubCategory\'),
        \'labels\' => $labels,
        \'hierarchial\' => true,
        \'show_ui\' => true,
        \'query_var\' => true,
        \'rewrite\' => array( \'slug\' => \'product-subcategory\'),
        )); 
}

add_action( \'init\', \'create_productcategory_taxonomy\', 0 );
add_action( \'init\', \'create_product_subcategory_taxonomy\', 0 );

1 个回复
最合适的回答,由SO网友:Chris_O 整理而成

层次是指术语之间的关系,而不是分类法与另一个分类法的关系。非层次分类法就像标签一样,它们没有父级或子级。层次分类法意味着术语可以有父项和子项。

分类法=类别

类别术语:

蓝色产品(parent term)

浅蓝色产品(子术语)深蓝色产品(子术语)红色产品(parent term)

深红色产品(子术语)浅红色产品(子术语)也在您的上述代码中更改:

\'hierarchial\' => true,
收件人:

\'hierarchical\' => true,

结束

相关推荐