我相信有这样的需求的人应该不会很多,但是只要有人有需求,就一定有解决办法。
常规情况下,我们看到的后台分类是下面的样子:
而这次的需求就是将“分类”两个字替换为自定义内内容,我这番描述大家可能不明白是什么意思,但是如果你看了下面的图片就会明白了:
除了这里的内容之外,还有很多地方的内容都可以修改,列表如下: [list title="" type="" unique_number="list_1132f7d41b4749bebeb0e2f1414a1bee"]name singular_name search_items popular_items all_items parent_item parent_item_colon edit_item view_item update_item add_new_item new_item_name separate_items_with_commas add_or_remove_items choose_from_most_used not_found no_terms items_list_navigation items_lists most_used back_to_items menu_name name_admin_bar[/list]
想要实现这个效果的代码如下:
add_filter( 'taxonomy_labels_category', 'filter_category_labels' ); function filter_category_labels( $labels ) { $labels->menu_name = '分类-》小姐姐'; return $labels; }
经过查看taxonomy_labels_{$taxonomy}过滤器,我了解到的就是这个过滤器貌似只能用于分类或者标签两种类型的页面,下面是我实践之后的效果:
当然,除了这些地方还有分类编辑页面或者其它和分类有关的页面都会进行修改,到底会修改哪些地方,我这边查看了一下相关的代码,并不知道是不是准确的:
$nohier_vs_hier_defaults = array( 'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ), 'singular_name' => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ), 'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ), 'popular_items' => array( __( 'Popular Tags' ), null ), 'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ), 'parent_item' => array( null, __( 'Parent Category' ) ), 'parent_item_colon' => array( null, __( 'Parent Category:' ) ), 'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ), 'view_item' => array( __( 'View Tag' ), __( 'View Category' ) ), 'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ), 'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ), 'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ), 'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ), 'add_or_remove_items' => array( __( 'Add or remove tags' ), null ), 'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ), 'not_found' => array( __( 'No tags found.' ), __( 'No categories found.' ) ), 'no_terms' => array( __( 'No tags' ), __( 'No categories' ) ), 'filter_by_item' => array( null, __( 'Filter by category' ) ), 'items_list_navigation' => array( __( 'Tags list navigation' ), __( 'Categories list navigation' ) ), 'items_list' => array( __( 'Tags list' ), __( 'Categories list' ) ), /* translators: Tab heading when selecting from the most used terms. */ 'most_used' => array( _x( 'Most Used', 'tags' ), _x( 'Most Used', 'categories' ) ), 'back_to_items' => array( __( '← Go to Tags' ), __( '← Go to Categories' ) ), 'item_link' => array( _x( 'Tag Link', 'navigation link block title' ), _x( 'Category Link', 'navigation link block description' ), ), 'item_link_description' => array( _x( 'A link to a tag.', 'navigation link block description' ), _x( 'A link to a category.', 'navigation link block description' ), ), );
也就是说这些替换会根据上面的内容进行一一对应替换。例如:edit_item对应替换的内容为Edit Tag或者Edit Category,根据你使用的过滤器不同则会进行不同的对应替换。
不知道这样的描述大家是否能明白,如果不明白可以联系我,提出问题,解决问题,进行交流才能共同进步。