编辑自定义帖子类型的类别时,所选的管理菜单是帖子的菜单(请参见屏幕截图)。这是一个bug吗。如果不是,那就有点不直观,对最终用户的体验也不太好。
Screenshot
代码:
function product_register_product_post_type() {
$box_post_type_args = array(
\'show_ui\' => true,
\'public\' => true,
\'taxonomies\' => array(
\'product_category\'
),
\'supports\' => array(
\'title\',
\'editor\',
\'thumbnail\',
\'slug\'
),
\'labels\' => array(
\'name\' => \'Products\',
\'singular_name\' => \'Product\',
\'add_new\' => \'Add New Product\',
\'add_new_item\' => \'Add New Product\',
\'edit_item\' => \'Edit Product\',
\'new_item\' => \'New Product\',
\'view_item\' => \'View Product\',
\'search_items\' => \'Search Products\',
\'not_found\' => \'No Products Found\',
\'not_found_in_trash\' => \'No Products Found In Trash\'
),
\'capability_type\' => \'page\',
\'rewrite\' => array( \'slug\' => \'produkt\' )
);
register_post_type( \'product\', $box_post_type_args );
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
\'name\' => _x( \'Categories\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Category\' ),
\'all_items\' => __( \'All Categories\' ),
\'parent_item\' => __( \'Parent Category\' ),
\'parent_item_colon\' => __( \'Parent Category:\' ),
\'edit_item\' => __( \'Edit Category\' ),
\'update_item\' => __( \'Update Category\' ),
\'add_new_item\' => __( \'Add New Category\' ),
\'new_item_name\' => __( \'New Genre Category\' ),
\'menu_name\' => __( \'Categories\' ),
);
register_taxonomy( \'product_category\', array( \'product\' ), array(
\'public\' => true,
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'produkter\' ),
));
}
add_action( \'init\', \'product_register_product_post_type\');