2012-04-20 41 views

Trả lời

10

thêm dòng này vào phần bạn register_post_type trong functions.php trong thư mục chủ đề của bạn

'taxonomies' => array('category', 'post_tag') 

Mã đầy đủ là trông như thế này

add_action('init', 'create_post_type'); 
function create_post_type() { 
register_post_type('posttypename', 
     array(
      'labels' => array(
       'name' => __('PostTypeName'), 
       'singular_name' => __('PostTypeName') 
      ), 
      'public' => true, 
      'has_archive' => true, 
      'rewrite' => array('slug' => 'posttypename'), 
      'supports' => array('title', 'editor', 'excerpt', 'custom-fields', 'thumbnail'), 
      'taxonomies' => array('category', 'post_tag') // this is IMPORTANT 
     ) 
    ); 
} 
+0

Đó là những gì tôi đang tìm kiếm: ''taxonomies' => array ('category', 'post_tag')'. Cảm ơn, Chandu! – enchance

4

Nếu bạn sử dụng 'taxonomies' => array('category', 'post_tag') thẻ sau đó wordpress bài mặc định của sẽ được hiển thị trong khu vực loại bài đăng tùy chỉnh.

Đây là cách sạch và độc đáo cho loại bài đăng "tin tức". Không được trộn với các loại bài đăng tùy chỉnh khác, thẻ mặc định, .. v.v.

Bạn có thể làm theo đầy đủ chi tiết của "create custom post types and tags with categories" from this link.

add_action('init', 'news_tag_taxonomies'); //change order add_action('init', 'news_tag_taxonomies', 0); 

//create two taxonomies, genres and tags for the post type "tag" 
function news_tag_taxonomies() 
{ 
    // Add new taxonomy, NOT hierarchical (like tags) 
    $labels = array(
    'name' => _x('Tags', 'taxonomy general name'), 
    'singular_name' => _x('Tag', 'taxonomy singular name'), 
    'search_items' => __('Search Tags'), 
    'popular_items' => __('Popular Tags'), 
    'all_items' => __('All Tags'), 
    'parent_item' => null, 
    'parent_item_colon' => null, 
    'edit_item' => __('Edit Tag'), 
    'update_item' => __('Update Tag'), 
    'add_new_item' => __('Add New Tag'), 
    'new_item_name' => __('New Tag Name'), 
    'separate_items_with_commas' => __('Separate tags with commas'), 
    'add_or_remove_items' => __('Add or remove tags'), 
    'choose_from_most_used' => __('Choose from the most used tags'), 
    'menu_name' => __('Tags'), 
); 

    register_taxonomy('tag','news',array(// replace your post type with "news" 
    'hierarchical' => false, 
    'labels' => $labels, 
    'show_ui' => true, 
    'update_count_callback' => '_update_post_term_count', 
    'query_var' => true, 
    'rewrite' => array('slug' => 'tag'), 
)); 
} 

Hy vọng điều này sẽ giúp đỡ.

+1

cảm ơn ... điều này rất hữu ích – mostafaznv

1

Tất cả tôi cần thêm ngoài mẫu mặc định WP codex là

'taxonomies' => array('post_tag'),  
Các vấn đề liên quan