【问题标题】:How seperate Post and Custom Post tyle categories?如何区分 Post 和 Custom Post 类型的类别?
【发布时间】:2013-11-22 08:23:34
【问题描述】:

我创建了一个自定义帖子类型并添加了“分类法”=>数组(“类别”)。但是当我添加一个类别时,它在帖子类别中也可见。有没有办法把它们分开?

add_action( 'init', 'create_News_postype' );
function create_News_postype() {
global $wp,$wp_rewrite;
$labels = array(
    'name' => _x('News', 'post type general name'),
    'singular_name' => _x('News', 'post type singular name'),
    'add_new' => _x('Add New', 'News'),
    'add_new_item' => __('Add New News'),
    'edit_item' => __('Edit News'),
    'new_item' => __('New News'),
    'view_item' => __('View News'),
    'search_items' => __('Search News'),
    'not_found' =>  __('No News found'),
    'not_found_in_trash' => __('No News found in Trash'),
    'parent_item_colon' => '',
);
$args = array(
    'label' => __('News'),
    'labels' => $labels,
    'public' => true,
    'can_export' => true,
    'show_ui' => true,
    '_builtin' => false,
    'capability_type' => 'post',
    'rewrite' => array( "slug" => 'News' ),
    'taxonomies'=>array('category'),
    'query_var' => true,
    'menu_icon' => '',  
    'menu_icon' => get_template_directory_uri().'/images/planner.png',  
    'hierarchical' => true,    
    'supports'=> array('title', 'thumbnail', 'editor', 'page-attributes') ,
    'show_in_nav_menus' => true,    
    'menu_position' => 6
);
register_post_type( 'new', $args);
}

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    是的,您可以将其他分类法用于自定义帖子类型:例如 news_category: 下面是代码

    function news_taxonomy() {  
     register_taxonomy(  
     'news_category',  
     'news',  
     array(  
        'hierarchical' => true,  
        'label' => 'Category',  
        'query_var' => true,  
        'rewrite' => array('slug' => 'news-category')  
     )  
    );  
    }  
    
     add_action( 'init', 'news_taxonomy' ); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 2014-12-16
      • 1970-01-01
      • 2020-11-03
      • 2015-08-22
      • 1970-01-01
      • 2011-02-20
      相关资源
      最近更新 更多