問題描述

我打算使用默認的”post tags” 分類法,在帖子和 2 個自定義帖子類型之間提供一組通用的標籤 (允許通過標籤進行收集/聚合) 。

我想將”post tags” 分類法重新命名為其他東西,比如 「一般標籤」,使其更清晰,特別是當這種分類法附加到其他自定義的帖子類型時。

所以,有沒有辦法在 Wordpress 中這樣做,或者我通過 SQL 來做到這一點。此外,任何人都知道,如果有一個期望,這種分類法存在與 Nane “post tags”

最佳解決方案

關於分類法的信息存儲在全局 $wp_taxonomies 數組中。如果您註冊了新的分類法,則將其添加為具有不同屬性的對象,包括在 UI 中使用的標籤。標準標籤和類別也會在每個頁面上加載,並在 init 上觸發 create_initial_taxonomies()功能。

由於它是一個簡單的對象數組,我們可以修改它,看看會發生什麼。我們感興趣的屬性是 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';
}

我沒有檢查到任何地方,你可能不得不自己改變主題,但這似乎是你想要的:

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。