我已经创建了菜单页和四个子菜单页。
public function onixion_admin_menu_option() {
add_menu_page(\'onixion\',\'Onixion\',\'manage_options\',\'onixion-admin-
menu\',array(&$this, \'onixion_main_page\' ),\'dashicons-chart-
area\',\'200\');
add_submenu_page(
\'onixion-admin-menu\',
\'scripts\',
\'Scripts\',
\'manage_options\',
\'scripts\',
array(&$this, \'onixion_scripts_page\' )
);
add_submenu_page(
\'onixion-admin-menu\',
\'custom_footer\',
\'Custom Footer\',
\'manage_options\',
\'custom_footer\',
array(&$this, \'onixion_custom_footer_page\' )
);
add_submenu_page(
\'onixion-admin-menu\',
\'file_upload\',
\'File Upload\',
\'manage_options\',
\'file_upload\',
array(&$this, \'onixion_file_upload_page\' )
);
add_submenu_page(
\'onixion-admin-menu\',
\'payments\',
\'Payments\',
\'manage_options\',
\'payments\',
array(&$this, \'onixion_payments_page\' )
);
}
一切似乎都很好,有一些子菜单页,上面有我打印的文本,以单独测试它们。
问题是第一个子菜单页是菜单页的副本。我想要的是,当有人单击主菜单选项:“Onixion”时,有不同的页面,并且只有我添加的子菜单页面(没有“Onixion”子菜单页面)。
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
您可以将子页面的slug设置为与父页面的slug相同。例如:
public function onixion_admin_menu_option() {
add_menu_page(\'onixion\',
\'Onixion\',
\'manage_options\',
\'onixion-admin-menu\',
array(&$this, \'onixion_main_page\' ),
\'dashicons-chart-area\',
\'200\'
);
add_submenu_page(
\'onixion-admin-menu\',
\'scripts\',
\'Scripts\',
\'manage_options\',
\'onixion-admin-menu\', // <-- here we set the same slug as for parent page
array(&$this, \'onixion_scripts_page\' )
);
add_submenu_page(
\'onixion-admin-menu\',
\'custom_footer\',
\'Custom Footer\',
\'manage_options\',
\'custom_footer\',
array(&$this, \'onixion_custom_footer_page\' )
);
add_submenu_page(
\'onixion-admin-menu\',
\'file_upload\',
\'File Upload\',
\'manage_options\',
\'file_upload\',
array(&$this, \'onixion_file_upload_page\' )
);
add_submenu_page(
\'onixion-admin-menu\',
\'payments\',
\'Payments\',
\'manage_options\',
\'payments\',
array(&$this, \'onixion_payments_page\' )
);
}