我是这样做的,当心,帖子太多了。
/* Add Menus
-----------------------------------------------------------------*/
add_action(\'admin_menu\', \'ch_essentials_admin\');
function ch_essentials_admin() {
/* Base Menu */
add_menu_page(
\'Essentials Theme\',
\'Essentials Theme\',
\'manage_options\',
\'ch-essentials-options\',
\'ch_essentials_index\');
}
现在,对于我的设置字段,删除了额外的字段,仅作为示例。
这用于“首页设置”和“首页选项卡”
add_action(\'admin_init\', \'ch_essentials_options\');
function ch_essentials_options() {
/* Front Page Options Section */
add_settings_section(
\'ch_essentials_front_page\',
\'Essentials Front Page Options\',
\'ch_essentials_front_page_callback\',
\'ch_essentials_front_page_option\'
);
add_settings_field(
\'featured_post\',
\'Featured Post\',
\'ch_essentials_featured_post_callback\',
\'ch_essentials_front_page_option\',
\'ch_essentials_front_page\'
);
这是我的标题选项,即“标题选项”选项卡
/* Header Options Section */
add_settings_section(
\'ch_essentials_header\',
\'Essentials Header Options\',
\'ch_essentials_header_callback\',
\'ch_essentials_header_option\'
);
add_settings_field(
\'header_type\',
\'Header Type\',
\'ch_essentials_textbox_callback\',
\'ch_essentials_header_option\',
\'ch_essentials_header\',
array(
\'header_type\'
)
);
注册设置
register_setting(\'ch_essentials_front_page_option\', \'ch_essentials_front_page_option\');
register_setting(\'ch_essentials_header_option\', \'ch_essentials_header_option\');
所有这些都封装在一个函数中,然后使用admin\\u init完成
/* Options
-----------------------------------------------------------------*/
add_action(\'admin_init\', \'ch_essentials_options\');
function ch_essentials_options() {
/* Code Shown above */
}
回拨电话:
/* Call Backs
-----------------------------------------------------------------*/
function ch_essentials_front_page_callback() {
echo \'<p>Front Page Display Options:</p>\';
}
function ch_essentials_header_callback() {
echo \'<p>Header Display Options:</p>\';
}
function ch_essentials_textbox_callback($args) {
$options = get_option(\'ch_essentials_header_option\');
echo \'<input type="text" id="\' . $args[0] . \'" name="ch_essentials_header_option[\' . $args[0] . \']" value="\' . $options[\'\' . $args[0] . \'\'] . \'"></input>\';
}
function ch_essentials_featured_post_callback() {
$options = get_option(\'ch_essentials_front_page_option\');
query_posts( $args );
echo \'<select id="featured_post" name="ch_essentials_front_page_option[featured_post]">\';
while ( have_posts() ) : the_post();
$selected = selected($options[featured_post], get_the_id(), false);
printf(\'<option value="%s" %s>%s</option>\', get_the_id(), $selected, get_the_title());
endwhile;
echo \'</select>\';
}
Now this is the display part, with the tabs..
如果您的设置部分和字段完全像这样完成,那么您将能够完美地完成选项卡。
/* Display Page
-----------------------------------------------------------------*/
function ch_essentials_index() {
?>
<div class="wrap">
<div id="icon-themes" class="icon32"></div>
<h2>Essentials Theme Options</h2>
<?php settings_errors(); ?>
<?php
$active_tab = isset( $_GET[ \'tab\' ] ) ? $_GET[ \'tab\' ] : \'front_page_options\';
?>
<h2 class="nav-tab-wrapper">
<a href="?page=ch-essentials-options&tab=front_page_options" class="nav-tab <?php echo $active_tab == \'front_page_options\' ? \'nav-tab-active\' : \'\'; ?>">Front Page Options</a>
<a href="?page=ch-essentials-options&tab=header_options" class="nav-tab <?php echo $active_tab == \'header_options\' ? \'nav-tab-active\' : \'\'; ?>">Header Options</a>
</h2>
<form method="post" action="options.php">
<?php
if( $active_tab == \'front_page_options\' ) {
settings_fields( \'ch_essentials_front_page_option\' );
do_settings_sections( \'ch_essentials_front_page_option\' );
} else if( $active_tab == \'header_options\' ) {
settings_fields( \'ch_essentials_header_option\' );
do_settings_sections( \'ch_essentials_header_option\' );
}
?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
----编辑-----
我确实在你的帖子中注意到,在选项卡部分的实际显示页面上有“elseif”而没有“elseif”