具有新分类的自定义帖子类型

时间:2014-11-13 作者:Adrian

我有一个名为“products”的CPT,所以在左边的菜单中有“products”和“add new”,我想在菜单中也有“product categories”,以便用户可以添加任意多的产品类别,然后当他们“add new product”时,他们可以将其分配给一个产品类别。

以下是我注册CPT的方式:

    register_post_type( \'products\',
// CPT Options
    array(
        \'labels\' => array(
            \'name\' => __( \'Products\' ),
            \'singular_name\' => __( \'product\' )
        ),
        \'public\' => true,
        \'has_archive\' => true,
        \'taxonomies\' => array( \'Product-categories\' ),
        \'hierarchical\' => true,
        \'rewrite\' => array(\'slug\' => \'products\'),
    )
);
如何在左侧的“产品”中获得“产品类别”分类菜单?

谢谢

1 个回复
最合适的回答,由SO网友:Computer Information Data Base 整理而成
  $labels = array(
\'name\' => _x( \'Categories\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Category\', \'taxonomy singular name\' ),
\'search_items\' =>  __( \'Search Types\',\'SkyDance\' ),
\'all_items\' => __( \'All Category\',\'SkyDance\' ),
\'parent_item\' => __( \'Parent Category\',\'SkyDance\' ),
\'parent_item_colon\' => __( \'Parent Category:\',\'SkyDance\' ),
\'edit_item\' => __( \'Edit Categories\',\'SkyDance\' ),
\'update_item\' => __( \'Update Category\',\'SkyDance\' ),
\'add_new_item\' => __( \'Add New Category,\'SkyDance\' ),
\'new_item_name\' => __( \'New Category Name\',\'SkyDance\' ),

);


    register_taxonomy(\'category-cpt\',array(\'cpt\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'category-cpt\' ),
 ));   
结束

相关推荐