WordPress Theme Options Framework
By Jeremy Clark
guides, tech, wordpress |
code, php, theme, wordpress | 1,497 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))
26 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




| (6 votes, average: 4.83 out of 5)
Designer
Oct 2nd 2008 @ 7:48 amHey man thanks a lot of this!
I’m still learning wordpress so this will be of great help
Could I ask you what license this framework has? Usable for commercial projects ? Soon I’m going to start designing wordpress themes and my friend will code them so can this be used? We will be making most of the themes opensource.
Thanks again, keep it up
Jeremy Clark
Oct 2nd 2008 @ 11:10 amUse as you see fit. Everything I release is GPL. Thanks for you interest.
Designer
Oct 9th 2008 @ 10:11 pmThanks
Adrian3
Oct 21st 2008 @ 6:16 pmThanks for this template. I have been looking around for this very thing. This is the first one I have found that made sense to me. Cheers!
Jeremy Clark
Oct 22nd 2008 @ 7:40 amGlad it helps. I’ll probably be improving on it shortly. I’m thinking of starting developing a new theme.
Adrian3
Oct 23rd 2008 @ 1:49 amJeremy,
So I used your framework to make a nice options page for my theme. Liking what I had made I wanted to turn it into a plugin so I could use it with other themes. Everything seems to work just fine pretty much without modification except for when I try to change the options. The path to the controlpanel.php doesn’t work because now the file is in the plugin directory, not the theme directory. This seems like it should be easy, but I frankly barely know what I am doing. Do you think you could help me out? The line in question I think is:
header(“Location: themes.php?page=controlpanel.php&saved=true”);
Thanks in advance for your help, and thanks again for providing this framework!
Reddy
Nov 1st 2008 @ 4:19 pmFantastic, just what I’ve been looking for! What I miss is a checkbox type though. Been trying to add it myself, but I must be doing something wrong
Jeremy Clark
Nov 1st 2008 @ 8:22 pmYeah I need to re work the frame work and include a checkbox area. Glad you found your answer though.
Jeremy Clark
Nov 7th 2008 @ 12:21 pmAfter looking at how to add check box support, I think it would be a little above my php skill right now. I’ll keep thinking on it though.
Reddy
Nov 1st 2008 @ 4:47 pmAh, nevermind, found some answers elsewhere.
teraOm
Nov 6th 2008 @ 12:29 pmINstead of a txt file download, you may want to zip the file and give us a zip file instead.
Safari and firefox open the txt file as such. One click download wold be a better option and also saves bandwidth..
Jeremy Clark
Nov 6th 2008 @ 12:41 pmVery true, I’ve added a download button.
Bobby
Nov 17th 2008 @ 11:43 pmDid theme options change in 2.7? I tried implementing them by hand and it broke my theme and now when I include your framework into my functions.php my theme breaks as well.