默认的“贴子标签”分类可以重命名吗?

时间:2010-11-17 作者:anu

我打算使用默认的“post-tags”分类法来跨帖子和2种自定义帖子类型提供一组通用的标签(以允许按标签进行收集/聚合)。

我想将“post tags”分类法重命名为其他分类法,如“general tags”,以使其更加清晰,尤其是当此分类法附加到其他自定义post类型时。

那么,有没有办法在Wordpress中实现这一点,或者我是通过SQL实现的。此外,任何人都知道nane“post标记”是否存在这种分类法

4 个回复
最合适的回答,由SO网友:Jan Fabry 整理而成

有关分类法的信息存储在全局$wp_taxonomies 大堆如果注册新的分类法,则会将其添加为具有不同属性的对象,包括要在UI中使用的标签。标准标记和类别也会在每个页面加载时注册,其中the create_initial_taxonomies() function 点燃的init.

因为它是一个简单的对象数组,所以我们可以修改它并查看发生了什么。我们感兴趣的房产有labelslabel.

add_action( \'init\', \'wpa4182_init\');
function wpa4182_init()
{
    global $wp_taxonomies;

    // The list of labels we can modify comes from
    //  http://codex.wordpress.org/Function_Reference/register_taxonomy
    //  http://core.trac.wordpress.org/browser/branches/3.0/wp-includes/taxonomy.php#L350
    $wp_taxonomies[\'post_tag\']->labels = (object)array(
        \'name\' => \'WPA 4182 Tags\',
        \'menu_name\' => \'WPA 4182 Tags\',
        \'singular_name\' => \'WPA 4182 Tag\',
        \'search_items\' => \'Search WPA 4182 Tags\',
        \'popular_items\' => \'Popular WPA 4182 Tags\',
        \'all_items\' => \'All WPA 4182 Tags\',
        \'parent_item\' => null, // Tags aren\'t hierarchical
        \'parent_item_colon\' => null,
        \'edit_item\' => \'Edit WPA 4182 Tag\',
        \'update_item\' => \'Update WPA 4182 Tag\',
        \'add_new_item\' => \'Add new WPA 4182 Tag\',
        \'new_item_name\' => \'New WPA 4182 Tag Name\',
        \'separate_items_with_commas\' => \'Separata WPA 4182 tags with commas\',
        \'add_or_remove_items\' => \'Add or remove WPA 4182 tags\',
        \'choose_from_most_used\' => \'Choose from the most used WPA 4182 tags\',
    );

    $wp_taxonomies[\'post_tag\']->label = \'WPA 4182 Tags\';
}
我没有到处检查它,您可能需要自己在主题中更改它,但这似乎满足了您的需要:

Tag metabox with new labels

SO网友:davidcondrey

您可以删除类别分类法,然后只需创建自己的类别分类法。

在我的示例中,我删除了post Categories分类法,并将其替换为Subjects分类法

add_action( \'init\', \'unregister_taxonomy\' );
function unregister_taxonomy() {
    global $wp_taxonomies;
    $taxonomy = \'category\';
    if ( taxonomy_exists($taxonomy) ){
        unset( $wp_taxonomies[$taxonomy] );
    }
}

function article_subjects() {
    $labels = array(
        \'name\'                       => _x( \'Subjects\', \'Taxonomy General Name\', \'dc\' ),
        \'singular_name\'              => _x( \'Subject\', \'Taxonomy Singular Name\', \'dc\' ),
        \'menu_name\'                  => __( \'Subjects\', \'dc\' ),
        \'all_items\'                  => __( \'All Items\', \'dc\' ),
        \'parent_item\'                => __( \'Parent Item\', \'dc\' ),
        \'parent_item_colon\'          => __( \'Parent Item:\', \'dc\' ),
        \'new_item_name\'              => __( \'New Subject\', \'dc\' ),
        \'add_new_item\'               => __( \'Add New Item\', \'dc\' ),
        \'edit_item\'                  => __( \'Edit Item\', \'dc\' ),
        \'update_item\'                => __( \'Update Item\', \'dc\' ),
        \'separate_items_with_commas\' => __( \'Separate items with commas\', \'dc\' ),
        \'search_items\'               => __( \'Search Items\', \'dc\' ),
        \'add_or_remove_items\'        => __( \'Add or remove items\', \'dc\' ),
        \'choose_from_most_used\'      => __( \'Choose from the most used items\', \'dc\' ),
        \'not_found\'                  => __( \'Not Found\', \'dc\' ),
    );
    $args = array(
        \'labels\'                     => $labels,
        \'hierarchical\'               => false,
        \'public\'                     => true,
        \'show_ui\'                    => true,
        \'show_admin_column\'          => true,
        \'show_in_nav_menus\'          => true,
        \'show_tagcloud\'              => true,
    );
    register_taxonomy( \'article_subjects\', array( \'post\' ), $args );
}
add_action( \'init\', \'article_subjects\', 0 );

SO网友:lemats

重命名特定类别标签:

add_action(\'init\', \'renameCategory\');
function renameCategory() {
    global $wp_taxonomies;

    $cat = $wp_taxonomies[\'category\'];
    $cat->label = \'My Categories\';
    $cat->labels->singular_name = \'My Categorie\';
    $cat->labels->name = $cat->label;
    $cat->labels->menu_name = $cat->label;
    //…
}
标签:http://codex.wordpress.org/Function_Reference/register_taxonomy#Arguments

SO网友:kaiser

From here

// hook the translation filters
add_filter(  \'gettext\',  \'change_post_to_article\'  );
add_filter(  \'ngettext\',  \'change_post_to_article\'  );

function change_post_to_article( $translated ) {
     $translated = str_ireplace(  \'Post\',  \'Article\',  $translated );  // ireplace is PHP5 only
     return $translated;
}
结束

相关推荐

Saving Taxonomy Terms

我有一个有趣的问题,希望有人能尽快回答。我已经创建了自己的metabox,它基于“我的metabox代码”(下面的列表)正确地显示了我创建的“event\\u types”分类中所有术语的下拉列表。我遇到的问题是,当从下拉列表中选择不同的术语并更新帖子时,能够保存/更新与帖子相关的术语。在对各种代码位进行修补之后,我发现通过手动将term\\u ID number[用逗号分隔]输入数组区域,我得到了我想要的结果。例如,如果在保存帖子时,函数将调用此代码wp_set_post_terms( $post_id