The code below is my theme options page (submenu - under "Appearance"). All options work fine except "select" and "radio"... They don't appear in the page as the other options do. I have been searching around the internet and trying different solutions for 3 days but there were no ways to make them appear. After that I would like to seperate the sections in different tabs which is also something I can't do. I have read the related documentation and some tutorials I found but nothing did the trick yet... Any help? Thanks!
<?php
$themename = "WIS";
$shortname = "wis";
$version = "1.1";
$option_group = $shortname.'_theme_option_group';
$option_name = $shortname.'_theme_options';
add_action('admin_init', 'wis_add_init');
function wis_add_init() {
$file_dir = get_template_directory_uri();
wp_enqueue_style("wisCss", $file_dir."/functions/theme-options.css", false, "1.0", "all");
wp_enqueue_script("wisScript", $file_dir."/functions/theme-options.js", false, "1.0");
}
// Create custom settings menu
add_action('admin_menu', 'wis_create_menu');
function wis_create_menu() {
global $themename;
//create new top-level menu
add_theme_page( __( $themename.' Theme Options' ), __( 'Theme Options' ), 'edit_theme_options', 'wisgentheoptpag', 'wis_settings_page' );
}
// Register settings
add_action( 'admin_init', 'register_settings' );
function register_settings() {
global $themename, $shortname, $version, $wis_options, $option_group, $option_name;
//register our settings
register_setting( $option_group, $option_name);
}
// Create theme options
global $wis_options;
$wis_options = array (
array("name" => __('RSS Feeds/Facebook/Twitter','wis'),
"type" => "section"),
array("name" => __('Set up social links.','wis'),
"type" => "section-desc"),
array("type" => "open"),
array("name" => __('Custom Feed URL','wis'),
"desc" => __('You can use your own feed URL (<strong>with http://</strong>). Paste your Feedburner URL here to let readers see it in your website.','wis'),
"id" => "feedurl",
"type" => "text",
"std" => get_bloginfo('rss2_url')),
array("name" => __('Delete Extra Feeds','wis'),
"desc" => __('WordPress adds feeds for categories, tags, etc., by default. Check this box to remove them and reduce the clutter.','wis'),
"id" => "cleanfeedurls",
"type" => "checkbox",
"std" => ""),
array("name" => __('Twitter ID','wis'),
"desc" => __('Your Twitter user name, please. It will be shown in the navigation bar. Leaving it blank will keep the Twitter icon supressed.','wis'),
"id" => "twitterid",
"type" => "text",
"std" => ""),
array("name" => __('Facebook Page','wis'),
"desc" => __('Link to your Facebook page, <strong>with http://</strong>. It will be shown in the navigation bar. Leaving it blank will keep the Facebook icon supressed.','wis'),
"id" => "facebookid",
"type" => "text",
"std" => ""),
array("type" => "close"),
//FOOTER
array("name" => __('Footer','wis'),
"type" => "section"),
array("name" => __('Customize footer of your website.','wis'),
"type" => "section-desc"),
array("type" =>"open"),
array("name" => __('Footer Text','wis'),
"desc" => __('Enter your footer text or HTML here.','wis'),
"id" => "footer_text",
"std" => "",
"type" => "textarea"),
array("name" => __('Hide Footer Navigation Links','wis'),
"desc" => __('Select to hide the navigation bar in the footer. If you want to customize the footer navigation, go to Menus under the Appearance tab in the dashboard.','wis'),
"id" => "hide_footer_nav",
"std" => "",
"type" => "checkbox"),
array("name" => __('Hide Footer Credits','wis'),
"desc" => __('Select to hide the credit line in the footer. Thanks for sending us a <strong>generous contribution</strong>.','wis'),
"id" => "hide_footer_credit",
array("name" => __('Theme Styles','wis'),
"type" => "section"),
array("name" => __('Choose a color scheme and add custom CSS styles.','wis'),
"type" => "section-desc"),
array("type" => "open"),
array("name" => __('Colour Scheme','wis'),
"desc" => __('Select a colour scheme for the theme. Future versions will have multiple styles.','wis'),
"id" => "alt_stylesheet",
"type" => "select",
"options" => $alt_stylesheets,
"std" => "default.css"),
array( "name" => __('Custom Styles','wis'),
"desc" => __('Want to add any custom CSS code? Put in here, and the rest is taken care of. This overrides any other stylesheets. eg: a.button{color:green}','wis'),
"id" => "custom_css",
"type" => "textarea",
"std" => ""),
array("type" => "close"),
"std" => "",
"type" => "checkbox"),
array( "type" => "close"),
//ADVERTISEMENTS --- POST ADS
array("name" => __('Advertisements','wis'),
"type" => "section"),
array("name" => __('Show ads on your blog.','wis'),
"type" => "section-desc"),
array("type" => "open"),
array("name" => __('Header Display Ad','wis'),
"desc" => __('You can show a display ad in header. Paste the code here for 600px by 60px ad.','wis'),
"id" => "topbanner",
"std" => "",
"type" => "textarea"),
array("name" => __('Ad Above Posts','wis'),
"desc" => __('Enter your Adsense code or other ad network code here. This ad will be displayed at the beginning of posts, below title on Post Pages and Pages with ad-supporting template. It is very basic and effective option for putting ads on your blog. If you want more functionality, get a specialized Ad plugin.','wis'),
"id" => "posttop_adcode",
"std" => "",
"type" => "textarea"),
array("name" => __('Ad Below Posts','wis'),
"desc" => __('Enter your Adsense code (or other ad network code) here. This ad will be displayed at the end of post content on Post Pages and Pages with ad-supporting template. Please make sure that you do not activate more ads than what is allowed by your ad network. Adsense allows up to 3 on one page.','wis'),
"id" => "postend_adcode",
"std" => "",
"type" => "textarea"),
array("type" => "close"),
//Analytics Code
array("name" => __('Tracking & Other Codes','wis'),
array("name" => __('Theme Styles','wis'),
"type" => "section"),
array("name" => __('Choose a color scheme and add custom CSS styles.','wis'),
"type" => "section-desc"),
array("type" => "open"),
array("name" => __('Colour Scheme','wis'),
"desc" => __('Select a colour scheme for the theme. Future versions will have multiple styles.','wis'),
"id" => "alt_stylesheet",
"type" => "select",
"options" => $alt_stylesheets,
"std" => "default.css"),
array( "name" => __('Custom Styles','wis'),
"desc" => __('Want to add any custom CSS code? Put in here, and the rest is taken care of. This overrides any other stylesheets. eg: a.button{color:green}','wis'),
"id" => "custom_css",
"type" => "textarea",
"std" => ""),
array("type" => "close"),
"type" => "section"),
array("name" => __('Insert Web tracking & analytics and other codes here.','wis'),
"type" => "section-desc"),
array("type" => "open"),
array("name" => __('Analytics & Tracking Code','wis'),
"desc" => __('You can paste your Google Analytics or other codes in this box. The codes will be automatically added to the footer.','wis'),
"id" => "analytics_code",
"type" => "textarea",
"std" => ""),
array("type" => "close")
);
function wis_settings_page() {
global $themename, $shortname, $version, $wis_options, $option_group, $option_name;
?>
<div class="wrap">
<div class="options_wrap">
<?php screen_icon(); ?><h2><?php echo $themename; ?> <?php _e('Theme Options','wis'); ?></h2>
<p class="top-notice"><?php _e('Customize your WordPress blog with these settings. ','wis'); ?></p>
<?php if ( isset ( $_POST['reset'] ) ): ?>
<?php // Delete Settings
global $wpdb, $themename, $shortname, $version, $wis_options, $option_group, $option_name;
delete_option('wis_theme_options');
wp_cache_flush(); ?>
<div class="updated fade"><p><strong><?php _e( $themename. ' options reset.' ); ?></strong></p></div>
<?php elseif ( isset ( $_REQUEST['updated'] ) ): ?>
<div class="updated fade"><p><strong><?php _e( $themename. ' options saved.' ); ?></strong></p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields( $option_group ); ?>
<?php $options = get_option( $option_name ); ?>
<?php foreach ($wis_options as $value) {
if ( isset($value['id']) ) { $valueid = $value['id'];}
switch ( $value['type'] ) {
case "section":
?>
<div class="section_wrap">
<h3 class="section_title"><?php echo $value['name']; ?>
<?php break;
case "section-desc":
?>
<span><?php echo $value['name']; ?></span></h3>
<div class="section_body">
<?php
break;
case 'text':
?>
<div class="options_input options_text">
<div class="options_desc"><?php echo $value['desc']; ?></div>
<span class="labels"><label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label></span>
<input name="<?php echo $option_name.'['.$valueid.']'; ?>" id="<?php echo $option_name.'['.$valueid.']'; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( isset( $options[$valueid]) ){ esc_attr_e($options[$valueid]); } else { esc_attr_e($value['std']); } ?>" />
</div>
<?php
break;
case 'textarea':
?>
<div class="options_input options_textarea">
<div class="options_desc"><?php echo $value['desc']; ?></div>
<span class="labels"><label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label></span>
<textarea name="<?php echo $option_name.'['.$valueid.']'; ?>" type="<?php echo $option_name.'['.$valueid.']'; ?>" cols="" rows=""><?php if ( isset( $options[$valueid]) ){ esc_attr_e($options[$valueid]); } else { esc_attr_e($value['std']); } ?></textarea>
</div>
<?php
break;
case 'select':
?>
<div class="options_input options_select">
<div class="options_desc"><?php echo $value['desc']; ?></div>
<span class="labels"><label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label></span>
<select name="<?php echo $option_name.'['.$valueid.']'; ?>" id="<?php echo $option_name.'['.$valueid.']'; ?>">
<?php foreach ($value['options'] as $option) { ?>
<option <?php if ($options[$valueid] == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?>
</select>
</div>
<?php
break;
case "radio":
?>
<div class="options_input options_select">
<div class="options_desc"><?php echo $value['desc']; ?></div>
<span class="labels"><label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label></span>
<?php foreach ($value['options'] as $key=>$option) {
if ( isset ( $options[$valueid] ) ) {
if ($key == $options[$valueid] ) {
$checked = "checked=\"checked\"";
} else {
$checked = "";
}
}else{
if($key == $value['std']){
$checked = "checked=\"checked\"";
}else{
$checked = "";
}
}?>
<input type="radio" id="<?php echo $option_name.'['.$valueid.']'; ?>" name="<?php echo $option_name.'['.$valueid.']'; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?><br />
<?php } ?>
</div>
<?php
break;
case "checkbox":
?>
<div class="options_input options_checkbox">
<div class="options_desc"><?php echo $value['desc']; ?></div>
<?php if( isset( $options[$valueid] ) ){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
<input type="checkbox" name="<?php echo $option_name.'['.$valueid.']'; ?>" id="<?php echo $option_name.'['.$valueid.']'; ?>" value="true" <?php echo $checked; ?> />
<label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label>
</div>
<?php
break;
case "close":
?>
</div><!--#section_body-->
</div><!--#section_wrap-->
<?php
break;
}
}
?>
<span class="submit">
<input class="button button-primary" type="submit" name="save" value="<?php _e('Save All Changes', 'wis') ?>" />
</span>
</form>
<form method="post" action="">
<span class="button-right" class="submit">
<input class="button button-secondary" type="submit" name="reset" value="<?php _e('Reset', 'wis') ?>" />
<input type="hidden" name="action" value="reset" />
<span id="caution"><?php _e('<span id="emph">Caution: All entries will be deleted from database.</span>','wis') ?></span>
</span>
</form>
</div><!--#options-wrap-->
</div>
<?php } ?>