I've created a wordpress theme and new in wordpress development I want to create option page to take some values from user and I've little bit done with that but confused where and how to save that data I want to create user interface in short.
|
update: All the following code should go into your functions.php file Probably the best (and definitely the easiest) way to make a Theme Options Page is to use the Wordpress Settings API. One note... everywhere you see THEME_NAME in my code, just replace this with some unique phrase (I use my theme name). First we need to tell WordPress that we are going to use some theme options. We do this by calling register_setting.
Next create the actual options page where your options will be set.
Now add the 'draw_theme_options_page' function used as a callback in 'add_theme_options_page' that will output the HTML for your Theme Options page. In this example you can see that I add three fields: 1) A Facebook Page URL 2) A Twitter Handle 3) A field to add twitter search terms
Now we need to add our sanitizing function. This function just ensures that no badly formatted data is saved into our database.
Now lastly we actually need to tie all these functions into the correct Wordpress Hooks so that our Theme Options page is added and works.
This code is almost verbatim what I use in my own Theme, but you may need to play with it a little bit and check for typos. Also for more information check out this post on adding Plugin Options |
||||
|
|
|
If you don't want to be bothered with coding the entire theme options, Options Framework Plugin can probably help you immensely. You just install this plugin and tweak the settings (what kind of user input you want to add, and so on). It will do the saving/retrieving/UI display tasks for you. There's also a theme version for that plugin, which you can include into your theme so you don't have to rely on using a plugin. |
|||
|
|
Here is a good article from the Wordpress theme developers, I am literally following it right now. |
|||
|
|
|
Otto has a really good blog post about the WordPress settings API. It does a lot of the work for you when it comes to saving values to the database. Here's the link: WordPress Settings API Tutorial |
|||
|
|
|
If you like to, you can use this plugin http://wordpress.org/extend/plugins/option-tree/ |
|||
|
|
