将设置字段添加到WP子菜单页面

时间:2017-07-07 14:48:30

标签: php wordpress menu backend

您好我目前正在关注如何向我创建的子菜单页面添加输入的指南。这是一张正在出现的图片。 http://imgur.com/a/St9wj。当我查看子菜单页面时。没有错误,只是没有显示文本字段。功能函数mytheme_general_name()未在第二个add_submenu_page中调用,但我不知道它有什么问题。

我复制了Here is my current两个正在使用的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>

0 个答案:

没有答案