WordPress Theme Options Framework
By Jeremy Clark
guides, tech, wordpress |
code, php, theme, wordpress | 4,692 views
Update: New Version
I’ve released a newly optimized version of the Theme Options Framework that now only makes two calls to the database rather than one call per option.
Recently I’ve been doing alot of work on my themes. I started off with the idea to make my theme work user friendly by adding a options page. So I started looking for how to do this, and came across this page and some useful code. So I took this and started modifying and trying different things and now I think I’ve got a very useful framework and I wanted to share with others. I’ll continue below as this will be fairly long post.
Update
Mike from Split Visonz has updated my framework to include a checkbox and multiple selection elements. Multiple selection is a dropdown list where you can select multiple items. You can download the new version below and I’ll explain the new additions as well.
First you’ll need to download the framework file:
After you have the controlpanel.php file uploaded to your server into your theme’s main directory you’ll need to add this line to your functions.php file
<?php require_once(TEMPLATEPATH . '/controlpanel.php'); ?>
Now you’ll need to start editing the array values to add your options.
$options = array (
array( "name" => "Radio Selection Set",
"desc" => "This is a descriptions",
"id" => $shortname."_radio",
"type" => "radio",
"std" => "3",
"options" => array("3", "2", "1")),
array( "name" => "Text Box",
"desc" => "This is a descriptions",
"id" => $shortname."_text_box",
"std" => "Some Default Text",
"type" => "text"),
array( "name" => "Bigger Text Box",
"desc" => "This is a descriptions",
"id" => $shortname."_bigger_box",
"std" => "Default Text",
"type" => "textarea"),
array( "name" => "Dropdown Selection Menu",
"desc" => "This is a descriptions",
"id" => $shortname."_dropdown_menu",
"type" => "select",
"std" => "Default",
"options" => array("Default", "Option 1", "Option 2")),
array( "name" => "Checkbox selection set",
"desc" => "This is a descriptions",
"id" => $shortname."_checkbox_menu",
"type" => "checkbox",
"std" => "Default",
"options" => array("Default", "Option 1", "Option 2")),
array( "name" => "Multiple selection box",
"desc" => "This is a descriptions",
"id" => $shortname."_multi_select_dropdown_menu",
"type" => "multiselect",
"std" => "Default",
"options" => array("Defaults", "Option 1s", "Option 2s"))
);
I’ve included in the framework examples of all the types of elements you can add, you can have as many options as you like. Notice there are four different types text, textarea, radio, select, multiple select, and checkbox. Also pay attention to the type of the file to the first two variables that you need to edit to reflect your theme.
$themename = "ThemeFullName"; $shortname = "themeShortName";
After you have your option page the way you like you’ll need some way of get the variables onto other pages of you theme. You’ll need to add these next few lines to every page on which you plan to use the theme variables.
<?php
global $options;
foreach ($options as $value) {
if($value['type']!="checkbox" and $value['type']!="multiselect"){
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else {
$$value['id'] = get_settings( $value['id'] ); }
}
else{
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = explode(",",$value['std']); } else {
$$value['id'] = explode(",",get_settings( $value['id'] )); }
}
} ?>
Now you can use the variables on this page. The variables will look like this let’s assume you set $shortname = “theme”, then your variables will look like this $theme_radio, $theme_text_box, $theme_bigger_box, $theme_dropdown_menu. Also keep in mind that you can add one than one of any kind of element, you can also rename any of the elements for easier variable management. Where “id” => $shortname.”_radio”, is defined you can change the _radio part to reflect what the option is actually for. For example I have mine set to chose how many columns my theme displays, so my variable is “id” => $shortname.”_columns”.
Update
To check the value of your multiple selection or checkbox variables you’ll need to use this. Where Item is the value that your checking that is selected or checked.
if(in_array("Item",$theme_checkbox))
No related posts.
30 Comments
Trackbacks / Pingbacks
- Mommy’s Idea Book » Blog Archive » Theme Options Framework
- Wordpress Theme Options Framework Updated. | Split-Visionz
- GrindSmart Magazine Design Articles & Tutorials » Blog Archive » WordPress: Giving Clients Access to Theme Options
- 10 Rare WordPress Theme Options Page Tutorials To Get You Started | CSS Reflex - Design Blog | Web Design | Inspiration and Resources for Designers
- 10+ WordPress Tutorials: How to Create an Options Page for Your WordPress Themes and Frameworks - WPConstructs.com
- Cómo crear una página de opciones para tu tema WordPress • wpargentina



| (10 votes, average: 4.50 out of 5)
Sore Throat Remedies
May 13th 2011 @ 10:55 pmoh cool, this information is really useful and definately is comment worthy!
Jatin Soni
Jun 19th 2011 @ 3:41 amThanks for this script.
But I am newbie and dont know how and which code i should add into my theme to reflect the value of the option. Also want to know is there any way to add image uploade button into the theme option panel?
I am using now toolkit but getting some issue with that I am not able to replace my header logo, so can you please let me know how to make option with your script where user can upload them own logo with own url as well as my theme has lots of image as its a photographer theme. So need to add lots of image upload option for my home.php template.
I would respect your reply.