未显示设置API设置部分

时间:2014-03-14 作者:Abhik

设置API对我来说总是有点困惑。

我正在尝试为我正在开发的子主题添加一个简单的主题选项页面。我想我是做错了什么,阻止了部分的出现。这个settings_fields() 虽然工作正常(正在打印表单中所有隐藏的字段),但节不是。这是我的代码,请帮我排除故障。

/********************************
    Add Theme Sub Menu Page
********************************/
function sr_theme_options_setup() {
    add_theme_page( \'Theme Options\', \'Theme Options\', \'edit_theme_options\', \'srchild\', \'ia_theme_page_settings\' );
}
add_action( \'admin_menu\', \'sr_theme_options_setup\' );


/*************************************
    Generate Options Page HTML
*************************************/
function ia_theme_page_settings() {
?>
    <div class="wrap">
        <?php screen_icon(\'themes\'); ?> <h2>Theme Settings</h2>
        <?php settings_errors( \'ia-settings-errors\' ); ?>
        <form id="form-ia-options" action="options.php" method="post" enctype="multipart/form-data">
                <?php
                    settings_fields(\'ia_options\');
                    do_settings_sections(\'ia_section_id\');
                ?>

                <p class="submit">
                    <input name="ia_options[submit]" id="submit_options_form" type="submit" class="button-primary" value="<?php esc_attr_e(\'Save Settings\', \'iathemes\'); ?>" />
                    <input name="ia_options[reset]" type="submit" class="button-secondary" value="<?php esc_attr_e(\'Reset Defaults\', \'iathemes\'); ?>" />
                </p>
        </form>
    </div>
<?php
}


/******************************************
    Register Settings/Section/Fields
******************************************/
function iathemes_init() {
    register_setting( \'ia_options\', \'ia_options\', \'ia_options_validate\' );

    // Add a form section for the Logo
    add_settings_section(\'ia_section_id\', __( \'Theme Settings\', \'iathemes\' ), \'ia_section_callback\', \'srchild\');

    // Add Logo uploader
    add_settings_field(\'ia_options_logo\',  __( \'Logo\', \'iathemes\' ), \'ia_options_logo\', \'srchild\', \'ia_section_id\');
}
add_action( \'admin_init\', \'iathemes_init\' );

function ia_section_callback() {
    ?>
        <p><?php echo \'Manage Theme Settings\'; ?></p>
    <?php
}

function ia_options_logo() {
    $options = get_option( \'ia_options\' );
    ?>
        <input type="text" id="logo_url" name="ia_options[site_logo]" value="<?php echo esc_url( $options[\'site_logo\'] ); ?>" />
        <input id="upload_logo_button" type="button" class="button" value="<?php _e( \'Upload Logo\', \'iathemes\' ); ?>" />
        <span class="description"><?php _e(\'Upload an image for the banner. Should be 300x40 pixels in size\', \'iatheme\' ); ?></span>
    <?php
}
请告诉我哪里做错了。

1 个回复
最合适的回答,由SO网友:birgire 整理而成

设置API可能令人费解;-)

替换:

do_settings_sections( \'ia_section_id\' );
使用

do_settings_sections( \'srchild\' );
显示定义的设置部分。

一般用途是:

do_settings_sections( $page );
其中:

$page (string)(必选)要输出其设置部分的页面的slug名称。这应该与中使用的页面名称匹配add_settings_section(). 默认值:无

根据法典(here).

结束

相关推荐