Answers:
有关分类法的信息存储在全局$wp_taxonomies
数组中。如果您注册了新的分类法,则会将其添加为具有不同属性的对象,包括在UI中使用的标签。每次加载页面时,标准标签和类别也都通过该create_initial_taxonomies()
功能进行了注册。上触发init
。
由于它是对象的简单数组,因此我们可以对其进行修改并查看会发生什么。我们感兴趣的属性是labels
和label
。
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';
}
我没有到处检查过它,您可能必须自己更改主题,但这似乎可以满足您的要求:
您可以删除类别分类法,然后简单地创建自己的分类法。
在我的示例中,我删除了“类别”分类,并将其替换为“主题”分类
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 );
重命名特定类别标签:
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
从这里
// 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;
}