如何更改菜单页面位置

时间:2013-10-11 14:58:49

标签: php wordpress codex

在Wordpress中,我有这个示例主题选项页面,它出现在外观菜单页面下,但我希望它出现在自定义页面下(实时拍摄)。我有一个想法,我应该改变add_settings_section( $id, $title, $callback, $page )中的内容,但我已经尝试过,只会使选项页面信息消失。

function liveshot_server_theme_options_init() {
    register_setting(
        'liveshot_server_options',                // Options group, see settings_fields() call in                liveshot_server_theme_options_render_page()
        'liveshot_server_theme_options',          // Database option, see      liveshot_server_get_theme_options()
        'liveshot_server_theme_options_validate'  // The sanitization callback, see      liveshot_server_theme_options_validate()
    );

    // Register our settings field group
    add_settings_section(
        'general',           // Unique identifier for the settings section
        '',                  // Section title (we don't want one)
        '__return_false',    // Section callback (we don't want anything)
        'theme_options'      // Menu slug, used to uniquely identify the page; see     liveshot_server_theme_options_add_page()
    );

    // Register our individual settings fields
    add_settings_field(
        'sample_checkbox',                                  // Unique identifier for the field for this section
        __( 'Sample Checkbox', '_s' ),                      // Setting field label
        'liveshot_server_settings_field_sample_checkbox',   // Function that renders the     settings field
        'theme_options',                                    // Menu slug, used to uniquely identify the page; see    liveshot_server_theme_options_add_page()
        'general'                                           // Settings section. Same as the first argument in the   add_settings_section() above
    );

    add_settings_field( 'sample_text_input', __( 'Sample Text Input', '_s' ), 'liveshot_server_settings_field_sample_text_input', 'theme_options', 'general' );
    add_settings_field( 'sample_select_options', __( 'Sample Select Options', '_s' ), 'liveshot_server_settings_field_sample_select_options', 'theme_options', 'general' );
    add_settings_field( 'sample_radio_buttons', __( 'Sample Radio Buttons', '_s' ), 'liveshot_server_settings_field_sample_radio_buttons', 'theme_options', 'general' );
    add_settings_field( 'sample_textarea', __( 'Sample Textarea', '_s' ), 'liveshot_server_settings_field_sample_textarea', 'theme_options', 'general' );
}

add_action( 'admin_init', 'liveshot_server_theme_options_init' );

/**
* Change the capability required to save the 'liveshot_server_options' options   group.
*
* @see liveshot_server_theme_options_init() First parameter to register_setting()   is the name of the options group.
* @see liveshot_server_theme_options_add_page() The edit_theme_options capability is used for viewing the page.
*
* @param string $capability The capability used for the page, which is  manage_options by default.
* @return string The capability to actually use.
*/
function liveshot_server_option_page_capability( $capability ) {
    return 'edit_theme_options';
}

add_filter( 'option_page_capability_liveshot_server_options',    'liveshot_server_option_page_capability' );

/**
* Add our theme options page to the admin menu.
*
* This function is attached to the admin_menu action hook.
*
* @since _s 1.0
*/
function liveshot_server_theme_options_add_page() {
    $theme_page = add_theme_page(
        __( 'Theme Options', '_s' ),                 // Name of page
        __( 'Theme Options', '_s' ),                 // Label in menu
        'edit_theme_options',                        // Capability required
        'theme_options',                             // Menu slug, used to uniquely identify the page
        'liveshot_server_theme_options_render_page'  // Function that renders the options page
    );
}

add_action( 'admin_menu', 'liveshot_server_theme_options_add_page' );

/**
* Returns an array of sample select options registered for _s.
*
* @since _s 1.0
*/

1 个答案:

答案 0 :(得分:0)

尝试使用add_submenu_page代替add_theme_page

http://codex.wordpress.org/Function_Reference/add_submenu_page