2011-06-06 29 views
8

在我的wordpress主題的functions.php中,我創建了一個名爲foobar的自定義文章類型。是否可以重複使用foobar帖子的默認類別和標籤?或者是否必須創建兩個分類法 - 一個用於類別,另一個用於標籤 - 才能實現此目的?重複使用默認類別/標籤分類法來定製帖子類型?

編輯:我想我已經通過使用創建自定義後類型的函數中的代碼解決了這個:

register_taxonomy_for_object_type('category', 'foobar'); 
register_taxonomy_for_object_type('post_tag', 'foobar'); 

我的規則。

+0

我已經回答了這個問題嘍。蛋糕給我! – CaseTA 2011-06-07 00:52:38

+4

你可以在下面回答你自己的問題(並接受它)。這對其他人很有幫助,因爲它標誌着問題的解決。作爲一邊你讓自己一些代表... – 2011-11-09 01:09:00

+0

大聲笑,我讀它,我認爲自己......「那麼這是什麼問題」。然後我閱讀你的評論。 – 2012-01-20 09:15:32

回答

5

可以一舉兩得,使用taxonomies鍵時registering the post type

$product_labels = array(
     'name' => _x('Products', 'post type general name'), 
     'singular_name' => _x('Product', 'post type singular name'), 
     'add_new' => _x('Add New', 'portfolio item'), 
     'add_new_item' => __('Add New Product'), 
     'edit_item' => __('Edit Product'), 
     'new_item' => __('New Product'), 
     'view_item' => __('View Product'), 
     'search_items' => __('Search Products'), 
     'not_found' => __('Nothing found'), 
     'not_found_in_trash' => __('Nothing found in Trash'), 
     'parent_item_colon' => '' 
    ); 
    $product_args = array(
     'labels' => $product_labels, 
     'public' => true, 
     'publicly_queryable' => true, 
     'show_ui' => true, 
     'query_var' => true, 
     'rewrite' => array('slug' => 'product'), 
     'capability_type' => 'post', 
     'hierarchical' => false, 
     'menu_position' => 2, 
     'supports' => array('title','editor', 'author', 'thumbnail', 'excerpt', 'comments', 'revisions', 'page-attributes', 'custom-fields',), 
     // Set the available taxonomies here 
     'taxonomies' => array('category', 'post_tag') 
    ); 
    register_post_type('product', $product_args); 
相關問題