总新手,我设法在面板中有一个单独的菜单项,包含一些子菜单页面(类似于设置,工具等元素。)
这是我使用的代码:
add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page() {
add_menu_page( 'custom menu title', 'Money Makers', 'manage_options', 'theme_options.php', '', plugins_url( 'myplugin/images/icon.png' ), 65 );
add_submenu_page( 'theme_options.php', 'Submenu 1', 'Submenu Page 1', 'manage_options', 'first-submenu-page', 'first_submenu_page_callback' );
add_submenu_page( 'theme_options.php', 'Submenu 2', 'Submenu Page 2', 'manage_options', 'second-submenu-page', 'second_submenu_page_callback' );
}
现在我想在第一个子菜单页面中添加一些带有字段的部分。我从一些教程中得到了这段代码:
function eg_settings_api_init() {
// Add the section to reading settings so we can add our
// fields to it
add_settings_section(
'eg_setting_section',
'Example settings section in reading',
'eg_setting_section_callback_function',
'first-submenu-page'
);
// Add the field with the names and function to use for our new
// settings, put it in our new section
add_settings_field(
'eg_setting_name',
'Example setting Name',
'eg_setting_callback_function',
'first-submenu-page',
'eg_setting_section'
);
// Register our setting so that $_POST handling is done for us and
// our callback function just has to echo the <input>
register_setting( 'first-submenu-page', 'eg_setting_name' );
} // eg_settings_api_init()
add_action( 'admin_init', 'eg_settings_api_init' );
它说“first-submenu-page”它曾经被写成'阅读' - 它显示在阅读子菜单页面的最底部。它可以将它改为'写',但当我把'first-submenu-page',页面(第一个子菜单)仍为空。
知道我做错了什么或者在这里做了什么?