添加一个子菜单选项页面可湿性粉剂后端菜单。我的代码出了什么问题?

时间:2017-07-07 作者:Jeron Gunn

您好,我目前正在遵循一个关于如何向我创建的子菜单页面添加输入的指南。Here 是显示内容的图片。当我查看子菜单页时。

没有错误,只是没有显示文本字段。函数函数mytheme_general_name() 第二天没有接到电话add_submenu_page, 但我看不出有什么问题。

我复制了这是我当前使用的两个php文件

文件名:function-admin.php

/*

@package Jeron

    ========================
        ADMIN PAGE
    ========================
*/

function mytheme_add_theme_options() {
    // Generate Theme Options Page
    add_menu_page(\'My Themes Theme Options\', \'Theme Options\', \'manage_options\', \'theme2_options\', \'mytheme_create_page\', get_template_directory_uri().\'/img/themeoptionsicon.png\', 110);

    // Generate Theme Options Sub Pages
    add_submenu_page(\'theme2_options\', \'Theme Options\', \'General\', \'manage_options\', \'theme2_options\', \'mytheme_create_page\');
    add_submenu_page(\'theme2_options\', \'Typography\', \'Typography\', \'manage_options\', \'theme_options_typography\', \'mytheme_create_typography_page\');
}

add_action(\'admin_menu\', \'mytheme_add_theme_options\');

// Activate Custom Settings
add_action(\'admin_init\', \'mytheme_custom_settings\');

function mytheme_custom_settings() {
    register_setting(\'mytheme-settings-group\', \'first_name\');
    add_settings_section(\'mytheme-general-options\', \'General Settings\', \'mytheme_general_options\', \'theme2_options\');
    add_settings_field(\'general-name\', \'First Name\', \'mytheme_general_name\', \'theme2_options\', \'mytheme_settings_group\');
}

function mytheme_general_options() {
    echo \'Customize Your Theme Options Below\';
}

function mytheme_general_name() {
    $firstName = esc_attr(get_option(\'first_name\'));
    echo \'<input type="text" name="first_name" value="\'.$firstName.\'" placeholder="First Name" />\';
}

function mytheme_create_page() {
    require_once(get_template_directory().\'/inc/templates/mytheme-admin.php\');
}

function mytheme_create_typography_page() {
    echo \'<h1>My Theme Typography</h1>\';
}

?>
文件名:mytheme-admin.php

<h1>My Theme Options</h1>
<?php settings_errors(); ?>
<form method="post" action="options.php">
    <?php settings_fields(\'mytheme_settings_group\');?>
    <?php do_settings_sections( \'theme2_options\' ); ?>
    <?php submit_button(); ?>
</form>

1 个回复
SO网友:Jeron Gunn

将mytheme\\u settings\\u group替换为mytheme general options,我认为这是分区id,不是唯一的id。感谢所有阅读此内容的人。希望它能帮助其他人。

结束