嗨,我刚刚学习如何使用设置API,我似乎不能到达同一页上的部分work.The第一部分完美地工作,并保存大雅,但第二个显示一个错误的保存:
Options Page not Found这是我的整个选项页面的代码:
<?php
/* ------------------------------------------------------------------------ *
* REGISTER MENU AND SUBMENU
* ------------------------------------------------------------------------ */
function thanathos_theme_menu(){
add_menu_page('Thanathos',
'Thanathos',
'administrator',
'thanathos_menu_id',
'thanathos_display'
);
}
add_action('admin_menu' ,'thanathos_theme_menu');
/*------------------------------------------------------------------------ *
* Social & Logo Options
* ------------------------------------------------------------------------ */
function thanathos_initialize_frontpage_options(){
if(false == get_option('thanathos_front_page_options')){
add_option('thanathos_front_page_options');
}
add_settings_section(
'thanathos_front_page',
'',
'thanathos_front_page_section_callback',
'thanathos_front_page_options'
);
add_settings_field(
'logo_path',
'Logo Path',
'thanathos_logo_path_url_callback',
'thanathos_front_page_options',
'thanathos_front_page'
);
register_setting(
'thanathos_front_page_options',
'thanathos_front_page_options',
'thanathos_front_page_options_sanitize'
);
}
add_action('admin_init', 'thanathos_initialize_frontpage_options');
function thanathos_front_page_section_callback(){}
function thanathos_logo_path_url_callback(){
$options = get_option('thanathos_front_page_options');
echo '<input type="text" id="logo" name="thanathos_front_page_options[logo_path]" value="' . $options['logo_path'] . '" />';
}
function thanathos_front_page_options_sanitize($input){
$output = array();
foreach ($input as $key => $val){
if(isset($input[$key])){
$output[$key] = strip_tags(stripslashes($input[$key]));
}
}
return apply_filters('thanathos_front_page_options' , $output , $input);
}
/* ------------------------------------------------------------------------ *
* Slider Options
* ------------------------------------------------------------------------ */
function thanathos_front_page_slider_options(){
if(false == get_option('thanathos_front_page_slider')){
add_option('thanathos_front_page_slider');
}
add_settings_section('thanathos_front_page_slider',
'',
'thanathos_front_page_slider_callback',
'thanathos_display',
'thanathos_front_page_slider'
);
}
add_action('admin_init', 'thanathos_front_page_slider_options');
function thanathos_front_page_slider_callback(){}
/* ------------------------------------------------------------------------ *
* Display on Thanathos Menu Page
* ------------------------------------------------------------------------ */
function thanathos_display(){
?> <style>
fieldset{
border:1px solid #ddd;
margin-top:20px;
padding-bottom: 20px;
}
legend{
margin-left:5px;
padding:0 5px;
color:#2481C6;
text-transform:uppercase;
}
p.submit{
margin-left: 10px;
}
td input{
width:360px;
}
</style>
<div class="wrap">
<div id="icon-themes" class="icon32"></div>
<h2>Thanathos General Options</h2>
<?php settings_errors(); ?>
<form method="post" action="options.php">
<fieldset>
<legend><strong>Logo and Social Options</strong></legend>
<?php
settings_fields( 'thanathos_front_page_options' );
do_settings_sections( 'thanathos_front_page_options' );
?>
</fieldset>
<?php submit_button(); ?>
</form>
<form method="post" action="options.php">
<fieldset>
<legend><strong>Slider Options</strong></legend>
<?php
settings_fields( 'thanathos_front_page_slider' );
do_settings_sections( 'thanathos_front_page_slider' );
?>
</fieldset>
<?php submit_button(); ?>
</form>
</div>
<?php
}
?>如果这不是将两个部分添加到同一页面的正确方法,那么什么是?
发布于 2012-08-23 19:05:31
下面是设置api的一个很好的教程。不过,如果你想把它作为一个整体来做,那就有点长了。
在part 5中,它解释了为什么你不能在一个页面上有两个settings_sections。
解决方案:使用标签。
这将帮助你解决你的问题。
http://wp.tutsplus.com/tutorials/the-complete-guide-to-the-wordpress-settings-api-part-1/
https://stackoverflow.com/questions/12090048
复制相似问题