0

我目前正在尝试了解设置 api,说实话,这有点困难。

我遇到的问题是,当我在子页面上提交表单时,它只是转到 options.php 页面?

到目前为止,这是我的代码

function setup_theme_admin_menus() {  


add_menu_page('Theme settings', 'SMate Options', 'manage_options',   
    'theme_settings', 'theme_settings_page');  

add_submenu_page('theme_settings',   
    'Front Page Elements', 'Front Page', 'manage_options',   
    'theme_settings_fp', 'theme_front_page_settings'); 

    add_submenu_page(
    'theme_settings',   
    'Team Option', 
    'Team Option', 
    'manage_options',   
    'theme_team_options', 
    'theme_team_settings_fn'
    );  
}


add_action('admin_init', 'initialize_theme_options'); 


function initialize_theme_options(){

register_setting('team_details', 'team_details' );

add_settings_section( 
    'member1',         
    'MEMBER 1',                  
    'theme_settings_fn', 
    'theme_team_options'
); 

add_settings_field(   
    't1',                  
    'Name',                 
    'text_fn',                       
    'theme_settings_team',
    'member1'
); 
add_settings_field(   
    'jt1',        
    'Job',      
    'text_fn',    
    'theme_settings_team', 
    'member1' 
);  
add_settings_field(   
    'lt1',
    'Description',  
    'longtext_fn',  
    'theme_settings_team',
    'member1' 
);
}

add_action('admin_init', 'initialize_theme_options');


function theme_team_settings_fn() { 


?>  

    <div class="wrap">  


        <div id="icon-themes" class="icon32"></div>  
        <h2>Sandbox Theme Options</h2>  


        <?php print_r('team_details');
         settings_errors(); ?>


        <form method="post" action="options.php">  
            <?php do_settings_sections('theme_team_options'); ?> 
            <?php submit_button(); ?>  
        </form>  

    </div><!-- /.wrap -->  
<?php  


}

任何帮助将不胜感激,因为我似乎已经碰壁了,所有教程似乎都使用 add_theme_page

4

1 回答 1

0

对于初学者来说,你register_settings('option_group','option_name);不应该是我会做的同名team_details_group,也许team_details_options,等等。

然后settings_fields('team_details_group')在表格内执行

<form method=post action=options.php>

紧随其后的是$options = get_option('team_details_options')

然后使用team_details_optionsto 在输入字段名称属性内保存任何数据,即:

<input type="text" name="team_details_options[memberName]" />

让我知道这是否有帮助或您需要更多信息。

于 2013-03-08T17:28:10.370 回答