添加菜单和子菜单,如:
add_action(\'admin_menu\', \'custom_plugin_menu\');
function custom_plugin_menu() {
$page_title = \'Parent Menu Title\';
$menu_title = \'Parent Menu Title\';
$capability = \'manage_options\';
$menu_slug = \'parent_menu_slug\';
$function = \'whatever_for_main_page_function\';
$icon_url = \'dashicons-admin-generic\';
$position = 4;
add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position);
$parent_slug = \'parent_menu_slug\';
$page_title = \'Submenu Page Title\';
$menu_title = \'Submenu Page Title\';
$capability = \'manage_options\';
$menu_slug = \'edit-tags.php?taxonomy=your_taxonomy_name&post_type=custom_post_type_name\';
$function = null;
$position = null;
add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function, $position);
}
最后:
add_filter(\'parent_file\', \'menu_highlight\');
function menu_highlight($parent_file) {
global $plugin_page, $submenu_file, $post_type, $taxonomy;
if (\'custom_post_type_name\' == $post_type) {
if ($taxonomy == \'your_taxonomy_name\') {
$plugin_page = \'edit-tags.php?taxonomy= your_taxonomy_name&post_type= custom_post_type_name\'; // the submenu slug
$submenu_file = \'edit-tags.php?taxonomy= your_taxonomy_name&post_type= custom_post_type_name\'; // the submenu slug
}
}
return $parent_file;
}
希望我把这些都写对了。在分类检查中嵌套任何其他if,并为其他帖子类型添加相同的if。