如何单独的帖子和自定义帖子类型?

时间:2013-11-22 08:23:35

标签: wordpress

我创建了一个自定义帖子类型并添加了'taxonomies'=>数组('category')。但是当我添加一个类别时,它也会在Post类别中显示。有没有办法分开它们?

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

1 个答案:

答案 0 :(得分:0)

是的,您可以使用其他分类法来定制帖子类型:例如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' );