我正在尝试在仅一个页面的admin菜单项下显示自定义分类法,即http://example.com/wp-admin/admin.php?page=bla。
根据WordPress开发人员的说法。register_taxonomyshow_in_menu
下的页面显示以下内容:
“某些字符串”-如果现有的顶级页面(例如“ tools.php”或“ edit.php?post_type = page”),则该帖子类型将作为该页面的子菜单放置。
这是否意味着分类法不能显示在那些分类法之外?
的PHP
<?php
// hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_book_taxonomies', 0 );
// create two taxonomies, genres and writers for the post type "book"
function create_book_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Genres', 'taxonomy general name' ),
'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
'search_items' => __( 'Search Genres' ),
'all_items' => __( 'All Genres' ),
'parent_item' => __( 'Parent Genre' ),
'parent_item_colon' => __( 'Parent Genre:' ),
'edit_item' => __( 'Edit Genre' ),
'update_item' => __( 'Update Genre' ),
'add_new_item' => __( 'Add New Genre' ),
'new_item_name' => __( 'New Genre Name' ),
'menu_name' => __( 'Genre' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_in_menu' => 'bla', // not working | tried admin.php?page=bla as well, also not working
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
);
register_taxonomy( 'genre', array( 'book' ), $args );
}
Run Code Online (Sandbox Code Playgroud)
我找到了解决此问题的方法,代码如下:
add_action( 'admin_menu', 'shmeh_menu' );
add_action( 'parent_file', 'menu_highlight' );
function shmeh_menu() {
add_submenu_page( 'bla', 'Shmeh', 'Shmeh', 'manage_options', 'edit-tags.php?taxonomy=shmeh');
}
function menu_highlight( $parent_file ) {
global $current_screen;
$taxonomy = $current_screen->taxonomy;
if ( $taxonomy == 'shmeh' ) {
$parent_file = 'bla';
}
return $parent_file;
}
Run Code Online (Sandbox Code Playgroud)