有什么方法可以在wordpress中使用单独的类别创建自定义帖子类型?

示例:

帖子类型“新闻”应具有类别“世界”和“本地”。
帖子类型“产品”应带有categories:“软件”和“硬件”
而且我不想选择将“软件”类别设置为“新闻”帖子类型。

有什么办法可以解决这个问题?

最佳答案

您可以通过以下示例代码创建自定义帖子类型:

function ts_post_type_test() {
    register_post_type( 'Test',
                array(
                'label' => __('Test'),
                'public' => true,
                'show_ui' => true,
                'show_in_nav_menus' => false,
                'menu_position' => 5,
                'capability_type' => 'post',
                'texonomies' => array('category'),
                'supports' => array( 'title','editor','thumbnail'),
                )
    );
}

wordpress网站链接:
http://codex.wordpress.org/Function_Reference/register_post_type

对于为特定职位创建单独类别,请使用以下链接:

http://codex.wordpress.org/Function_Reference/register_taxonomy

示例代码:
register_taxonomy('name of taxonomy', 'post name',array("hierarchical" => true,"label" => "Label Category","singular_label" => "label of taxonomy",'update_count_callback' => '_update_post_term_count','query_var' => true,'rewrite' => array( 'slug' => 'slug name of new registered taxonomy', 'with_front' => false ),'public' => true,'show_ui' => true,'show_tagcloud' => true,'_builtin' => false,'show_in_nav_menus' => false));

10-02 17:01