0

如何在安装 WordPress 主题时自动添加一些标签?

4

2 回答 2

0

您可以使用wp_insert_term以编程方式添加术语。请参阅函数参考。还有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' );
于 2013-07-03T19:40:50.440 回答
0

在主题register_taxonomy()function.php. 我WP Codex复制粘贴

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

这不会增加安装税,而是首次加载;无论如何我认为这应该是方式(如果你安装它,你会加载它)。

于 2013-07-03T19:32:53.050 回答