邮政类型的单独类别

时间:2012-02-10 13:50:53

标签: wordpress categories custom-post-type

有没有办法在wordpress中创建包含单独类别的自定义帖子类型?

示例

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

有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:12)

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

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));