【问题标题】:Separate categories for post types帖子类型的单独类别
【发布时间】:2012-02-10 13:50:53
【问题描述】:

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

示例

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

有什么办法可以解决吗?

【问题讨论】:

  • 相信您的编辑,您真的需要这种粒度级别吗?

标签: wordpress categories custom-post-type


【解决方案1】:

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

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

【讨论】:

  • 不确定singular_label,链接的文档中似乎没有这样的内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-11
  • 2012-07-30
  • 2015-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-24
相关资源
最近更新 更多