2013-07-03 36 views

回答

0

register_taxonomy()放在主題的function.php中。我複製粘貼from WP食品

// Add new taxonomy, NOT hierarchical (like tags) 
$labels = array(
    'name'      => _x('Writers', 'taxonomy general name'), 
    'singular_name'    => _x('Writer', 'taxonomy singular name'), 
    'search_items'    => __('Search Writers'), 
    'popular_items'    => __('Popular Writers'), 
    'all_items'     => __('All Writers'), 
    'parent_item'    => null, 
    'parent_item_colon'   => null, 
    'edit_item'     => __('Edit Writer'), 
    'update_item'    => __('Update Writer'), 
    'add_new_item'    => __('Add New Writer'), 
    'new_item_name'    => __('New Writer Name'), 
    'separate_items_with_commas' => __('Separate writers with commas'), 
    'add_or_remove_items'  => __('Add or remove writers'), 
    'choose_from_most_used'  => __('Choose from the most used writers'), 
    'not_found'     => __('No writers found.'), 
    'menu_name'     => __('Writers'), 
); 

$args = array(
    'hierarchical'   => false, 
    'labels'    => $labels, 
    'show_ui'    => true, 
    'show_admin_column'  => true, 
    'update_count_callback' => '_update_post_term_count', 
    'query_var'    => true, 
    'rewrite'    => array('slug' => 'writer'), 
); 

register_taxonomy('writer', 'book', $args); 

這不會對安裝加稅,但在第一次加載;無論如何,我認爲這應該是(如果你安裝它,你會加載它)。

+0

標籤已經預先註冊分類... – Ennui

+0

你是對的某種方式。但是,標籤只是您可以分配給post_type的分類標準也是事實。您的方法更適合通用稅(在這種情況下是標籤),但我的方法也適用於更自定義的分類樹。不是嗎? –

+0

是的。我只是指出他似乎並沒有這樣問:p – Ennui

0

您可以使用wp_insert_term以編程方式添加條款。請參閱function reference。還有wp_update_term。這些功能適用於所有類型的術語 - 類別和標籤以及自定義分類法。

您需要將這些函數放入函數中的functions.php文件中,然後將其添加到init操作中。

我還沒有測試此代碼,但它應該工作:

function add_tags() { 
    wp_insert_term(
     'Butts', // the tag/term name 
     'tags', // the taxonomy name 
     array(
      'description' => 'Posts about Butts', 
      'slug' => 'butts' 
    )); 
add_action('init', 'add_tags');