how to creat theme option in wordpress
-
hi friends.I had created wordpress theme in that i want to include theme option. let me clear how to creat theme option in wordpress. i had try using the following code but not working……….if any one know how to creat theme option pls give clear explanation.
<?php // Theme Options // Specky Geek -- http://www.speckygeek.com $themename = "Amazepixels"; $shortname = "amaze"; $version = "1.0"; // Create theme options global $options; $options = array ( array( "name" => "General", "type" => "section"), array( "type" => "open"), array( "name" => "Logo URL:", "desc" => "Enter the URL of your logo image", "id" => $shortname."_logo_url", "type" => "text", "std" => ""), array( "name" => "Custom Favicon", "desc" => "Paste the full URL of Png/Gif image that will represent your website's favicon (16px x 16px) ", "id" => $shortname."_custom_favicon", "type" => "text", "std" => get_bloginfo('url') ."/favicon.ico"), array( "name" => "Custom Feed URL", "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.", "id" => $shortname."_feedurl", "type" => "text", "std" => get_bloginfo('rss2_url')), array( "name" => "Delete Extra Feeds", "desc" => "WordPress adds feeds for categories, tags, etc., by default. Check this box to remove them and reduce the clutter.", "id" => $shortname."_cleanfeedurls", "type" => "checkbox", "std" => ""), array( "name" => "Twitter ID'", "desc" => "Your Twitter user name, please. It will be shown in the navigation bar. Leaving it blank will keep the Twitter icon supressed.", "id" => $shortname."_twitterid", "type" => "text", "std" => ""), array( "name" => "Facebook Page", "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 suppressed.", "id" => $shortname."_facebookid", "type" => "text", "std" => ""), array( "type" => "close"), array( "name" => "Footer", "type" => "section"), array( "type" => "open"), array( "name" => "Footer Text", "desc" => "Paste your text, copyright statements, etc., here.", "id" => $shortname."_footer_text", "type" => "textarea", "std" => ""), array( "name" => "Analytics/Tracking Code", "desc" => "You can paste your Google Analytics or other website tracking code in this box. This will be automatically added to the footer.", "id" => $shortname."_analytics_code", "type" => "textarea", "std" => ""), array( "type" => "close"), array( "name" => "Advertisement Code", "type" => "section"), array( "type" => "open"), array( "name" => "Adsense Code", "desc" => "Enter your Adsense code (or other ad network code) here.", "id" => $shortname."_adcode", "std" => "", "type" => "textarea"), array( "type" => "close"), ); function amaze_add_admin() { global $themename, $shortname, $options; if ( isset ( $_GET['page'] ) && ( $_GET['page'] == basename(__FILE__) ) ) { if ( isset ($_REQUEST['action']) && ( 'save' == $_REQUEST['action'] ) ){ foreach ( $options as $value ) { if ( array_key_exists('id', $value) ) { if ( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } } } header("Location: admin.php?page=".basename(__FILE__)."&saved=true"); } else if ( isset ($_REQUEST['action']) && ( 'reset' == $_REQUEST['action'] ) ) { foreach ($options as $value) { if ( array_key_exists('id', $value) ) { delete_option( $value['id'] ); } } header("Location: admin.php?page=".basename(__FILE__)."&reset=true"); } } add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'amaze_admin'); add_submenu_page(basename(__FILE__), $themename . ' Options', 'Theme Options', 'administrator', basename(__FILE__),'amaze_admin'); // Default } function amaze_add_init() { $file_dir=get_bloginfo('template_directory'); wp_enqueue_style("amazeCss", $file_dir."/includes/admin/style.css", false, "1.0", "all"); wp_enqueue_script("amazeScript", $file_dir."/includes/admin/theme-options.js", false, "1.0"); } function amaze_admin() { global $themename, $shortname, $version, $options; $i=0; if ( isset ($_REQUEST['saved']) && ($_REQUEST['saved'] ) )echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>'; if ( isset ($_REQUEST['reset']) && ($_REQUEST['reset'] ) ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>'; ?> <div class="wrap "> <div class="options_wrap"> <h2 class="settings-title"><?php echo $themename; ?> Settings</h2> <form method="post"> <?php foreach ($options as $value) { switch ( $value['type'] ) { case "section": ?> <div class="section_wrap"> <h3 class="section_title"><?php echo $value['name']; ?></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 $value['id']; ?>"><?php echo $value['name']; ?></label></span> <input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo stripslashes(get_option( $value['id']) ); } else { echo $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 $value['id']; ?>"><?php echo $value['name']; ?></label></span> <textarea name="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_option( $value['id'] ) != "") { echo stripslashes(get_option( $value['id']) ); } else { echo $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 $value['id']; ?>"><?php echo $value['name']; ?></label></span> <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"> <?php foreach ($value['options'] as $option) { ?> <option <?php if (get_option( $value['id'] ) == $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 $value['id']; ?>"><?php echo $value['name']; ?></label></span> <?php foreach ($value['options'] as $key=>$option) { $radio_setting = get_option($value['id']); if($radio_setting != ''){ if ($key == get_option($value['id']) ) { $checked = 'checked="checked"'; } else { $checked = ''; } }else{ if($key == $value['std']){ $checked = 'checked="checked"'; }else{ $checked = ""; } }?> <input type="radio" name="<?php echo $value['id']; ?>" 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(get_option($value['id'])){ $checked = 'checked="checked"'; }else{ $checked = "";} ?> <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> /> <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label> </div> <?php break; case "close": $i++; ?> <span class="submit"><input name="save<?php echo $i; ?>" type="submit" value="Save Changes" /></span> </div><!--#section_body--> </div><!--#section_wrap--> <?php break; } } ?> <input type="hidden" name="action" value="save" /> <span class="submit"> <input name="save" type="submit" value="Save All Changes" /> </span> </form> <form method="post"> <span class="submit"> <input name="reset" type="submit" value="Reset All Options" /> <input type="hidden" name="action" value="reset" /> </span> </form> <br/> </div><!--#options-wrap--> </div><!--#wrap--> <?php } add_action('admin_init', 'amaze_add_init'); add_action('admin_menu' , 'amaze_add_admin'); ?>thank u…
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘how to creat theme option in wordpress’ is closed to new replies.