编辑自定义帖子类型类别时出现错误?

时间:2011-05-13 作者:Joakim

编辑自定义帖子类型的类别时,所选的管理菜单是帖子的菜单(请参见屏幕截图)。这是一个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\');

2 个回复
SO网友:kaiser

注册自定义过帐类型时,需要设置自定义分类,然后通过“分类”参数添加自定义税的名称。

SO网友:Chip Bennett

也许是因为您将自定义分类命名为“类别”?

// Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
        \'name\' => _x( \'Categories\', \'taxonomy general name\' ),
        // ...
。。。

register_taxonomy( \'product_category\', array( \'product\' ), array(
        // ...
        \'labels\' => $labels,
尝试更改$labels 传递给的数组register_taxonomy.

结束