2013-07-03 37 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');