<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AEXT.NET MAGAZINE &#187; Theme</title>
	<atom:link href="http://aext.net/tag/theme/feed/" rel="self" type="application/rss+xml" />
	<link>http://aext.net</link>
	<description>How to Create a Website</description>
	<lastBuildDate>Wed, 30 May 2012 05:03:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>WordPress Theme Design with Options Administration</title>
		<link>http://aext.net/2009/10/wordpress-theme-design-with-options-adminstration/</link>
		<comments>http://aext.net/2009/10/wordpress-theme-design-with-options-adminstration/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 23:35:23 +0000</pubDate>
		<dc:creator>Lief</dc:creator>
				<category><![CDATA[Popular]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[get_option()]]></category>
		<category><![CDATA[Options]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Wordpress Theme]]></category>

		<guid isPermaLink="false">http://aext.net/?p=921</guid>
		<description><![CDATA[<p><a href="http://aext.net/theme/platinoom" title="Platinoom - Premium WordPress Themes"><img src="http://aext.net/wp-content/uploads/2011/04/platinoom_wordpress_theme.png" alt="ThemeKiss" /></a></p><p style="float: right;"><a href="http://api.tweetmeme.com/share?url=http://aext.net/2009/10/wordpress-theme-design-with-options-adminstration/&service=su.pr&service_api=b57727e991c454bd2b2c62ff71462c79"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://aext.net/2009/10/wordpress-theme-design-with-options-adminstration/" height="61" width="51" /></a></p>Are you running Wordpress? And how are you controlling all options of your current wordpress theme? Wordpress offers you get_option() function to get the options of your wordpress. However, all of default options wordpress gives to you are not enough. You maybe want to add more options that easy to implement on your theme design. How to do that? This tutorial will help you create options and administrate them in your Wordpress Administration Panel <a href="http://aext.net/2009/10/wordpress-theme-design-with-options-adminstration/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://aext.net/theme/platinoom" title="Platinoom - Premium WordPress Themes"><img src="http://aext.net/wp-content/uploads/2011/04/platinoom_wordpress_theme.png" alt="ThemeKiss" /></a></p><p style="float: right;"><a href="http://api.tweetmeme.com/share?url=http://aext.net/2009/10/wordpress-theme-design-with-options-adminstration/&service=su.pr&service_api=b57727e991c454bd2b2c62ff71462c79"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://aext.net/2009/10/wordpress-theme-design-with-options-adminstration/" height="61" width="51" /></a></p><p>Are you running WordPress? And how are you controlling all options of your current wordpress theme? WordPress offers you get_option() function to get the options of your wordpress. However, all of default options wordpress gives to you are not enough. You maybe want to add more options that easy to implement on your theme design. How to do that? This tutorial will help you create options and administrate them in wordpress admin page.</p>
<p><span id="more-921"></span></p>
<div class="demo-download">
<ul>
<li><a class="downloadit" href="http://www.box.net/shared/yd1yyts3ev">Download</a></li>
</ul>
</div>
<h3>Theme Options</h3>
<hr />
<p>All of wordpress options are stored in the database under table wp_options, and your theme options will be so. Let&#8217;s see the structure of wp_options table, all the field, and data type of each are:</p>
<ul class="mylist">
<li>option_id &#8211; BIGINT</li>
<li>blog_id &#8211; INTEGER</li>
<li><strong>option_name</strong> &#8211; VARCHAR</li>
<li><strong>option_value</strong> &#8211; LONGTEXT</li>
<li>autoload &#8211; VARCHAR</li>
</ul>
<p>All you need are the fields in bold, because you use the function get_option() to get options with the name in option_name filed, and the option_value, of course is what you need to get.<br />
The default using of get_option() is:</p>
<pre class="php"><span style="color: #0000bb;">&lt;?phpÂ </span><span style="color: #007700;">echoÂ </span><span style="color: #0000bb;">get_option</span><span style="color: #007700;">(Â </span><span style="color: #0000bb;">$showÂ </span><span style="color: #007700;">);Â </span><span style="color: #0000bb;">?&gt;</span></pre>
<p>And the code above is the same as the query below:</p>
<div class="bigimage"><img class="alignnone size-full wp-image-929" title="get_option() funtion and return value" src="http://aext.net/wp-contents/uploads/2009/09/get_option-funtion-and-return-value.jpg" alt="get_option() funtion and return value" width="500" /></div>
<p>However, you should know the difference is the function will return FASLE if the desired option does not exist, or no value is associated with it, but the query will return null.</p>
<h3>How do we process an option?</h3>
<hr />
<p>At first, you have to declare an option on your theme functions.php file. The simple option is fine for configuration and getting will be declared as:</p>
<pre class="html"><span style="color: #236e25;"><em>// theme options </em></span><span style="color: #825900;">$options</span> = <span style="color: #881350;">array</span>(

Â Â <span style="color: #881350;">array</span>(
Â Â Â Â <span style="color: #eb7300;">"name"</span> Â Â Â Â Â =&gt; <span style="color: #eb7300;">"Option Title"</span>,
Â Â Â Â <span style="color: #eb7300;">"desc"</span> Â Â Â Â Â =&gt; <span style="color: #eb7300;">"Option Description"</span>,
Â Â Â Â <span style="color: #eb7300;">"id"</span> Â Â Â Â Â Â Â =&gt; <span style="color: #eb7300;">"Option Unique ID"</span>, <span style="color: #236e25;"><em>//This is option_name filed in the database </em></span>Â Â Â Â <span style="color: #eb7300;">"default"</span> Â Â =&gt; <span style="color: #eb7300;">"10"</span>), <span style="color: #236e25;"><em>//Its default value </em></span>
);</pre>
<p>Your theme setting page will as good as display as image below:</p>
<div class="bigimage"><img class="alignnone size-full wp-image-933" title="get_option - The option display on setting page" src="http://aext.net/wp-contents/uploads/2009/09/get_option-The-option-display-on-setting-page.jpg" alt="get_option - The option display on setting page" width="500" height="217" /></div>
<p>Hey, but before getting a result above, we have to write some code for displaying. As an example, I will make a block of an option. In my case, I want to set an option for number of Community News article will be displayed on the homepage.</p>
<p>Declare the option:</p>
<pre class="php"><span style="color: #dd0000;">&lt;?php</span>

<span style="color: #825900;">$options</span> = <span style="color: #881350;">array</span>(

  <span style="color: #881350;">array</span>(    
    <span style="color: #eb7300;">"name"</span> =&gt; <span style="color: #eb7300;">"&lt;strong&gt;Homepage Community Entries&lt;/strong&gt;"</span>,
    <span style="color: #eb7300;">"desc"</span> =&gt; <span style="color: #eb7300;">"Select the number of Community entries that should appear on the Index page"</span>,
    <span style="color: #eb7300;">"id"</span> =&gt; <span style="color: #eb7300;">"aext_numcomnews"</span>,
    <span style="color: #eb7300;">"default"</span> =&gt; <span style="color: #eb7300;">"10"</span>),

);

<span style="color: #dd0000;">?&gt;</span></pre>
<p>The code to display:</p>
<pre class="php"> <span style="color: #881280;">&lt;div </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"stuffbox"</span><span style="color: #881280;">&gt;</span>
  <span style="color: #881280;">&lt;h3&gt;</span>Homepage Setting<span style="color: #881280;">&lt;/h3&gt;</span>
  <span style="color: #881280;">&lt;div </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"inside"</span><span style="color: #881280;">&gt;</span>
    <span style="color: #881280;">&lt;table </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"form-table"</span><span style="color: #994500;">style</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"width: auto"</span><span style="color: #881280;">&gt;</span>
    <span style="color: #dd0000;">&lt;?php</span>
     <span style="color: #881350;">foreach</span>(<span style="color: #825900;">$options</span> <span style="color: #881350;">as</span> <span style="color: #825900;">$value</span>) {
      <span style="color: #881350;">switch</span>( <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>] ) {
        <span style="color: #881350;">case</span> <span style="color: #eb7300;">"aext_numcomnews"</span>: <span style="color: #dd0000;">?&gt;</span>
        <span style="color: #881280;">&lt;tr&gt;</span>
        <span style="color: #881280;">&lt;th </span><span style="color: #994500;">scope</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"row"</span><span style="color: #881280;">&gt;</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'name'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #881280;">&lt;br /&gt;</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'desc'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #881280;">&lt;/th&gt;</span>
        <span style="color: #881280;">&lt;td&gt;</span>
         <span style="color: #881280;">&lt;input </span><span style="color: #994500;">name</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #1a1aa6;">"</span><span style="color: #881280;">                 </span><span style="color: #994500;">id</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #1a1aa6;">"</span><span style="color: #994500;">type</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"text"</span><span style="color: #881280;">                 </span><span style="color: #994500;">value</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #003369;">get_option</span>(<span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>])?<span style="color: #661aa9;">printf</span>(<span style="color: #003369;">get_option</span>(<span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>])): <span style="color: #661aa9;">printf</span>(<span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'default'</span>]) <span style="color: #dd0000;">?&gt;</span><span style="color: #1a1aa6;">"</span><span style="color: #881280;"> /&gt;</span>
        <span style="color: #881280;">&lt;/td&gt;</span>
        <span style="color: #881280;">&lt;/tr&gt;</span>

      <span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">break</span>;
        }
    }
    <span style="color: #dd0000;">?&gt;</span>
   <span style="color: #881280;">&lt;/table&gt;</span>
  <span style="color: #881280;">&lt;/div&gt;</span>
 <span style="color: #881280;">&lt;/div&gt;</span></pre>
<p>And, here is the result &#8230;</p>
<div class="bigimage"><img class="alignnone size-full wp-image-944" title="get_option - display in theme setting page" src="http://aext.net/wp-contents/uploads/2009/10/get_option-display-in-theme-setting-page1.jpg" alt="get_option - display in theme setting page" width="500" height="200" /></div>
<h3>Where&#8217;s the Theme Setting Page?</h3>
<hr />
<p>We already write a lot of code for theme setting page, but we can not edit/update the option without display page. Let&#8217;s see how to add a link which link to theme setting page.<br />
At first, you have to understand what your functions.php looks like. To make it easy, the name and the content of this functions.php are:</p>
<pre class="php"><span style="color: #dd0000;">&lt;?php</span>

<span style="color: #825900;">$options</span> = <span style="color: #881350;">array</span>(

  <span style="color: #236e25;"><em>//All your options will be declared here </em></span>   
);

<span style="color: #236e25;"><em>//This function is used for processing </em></span><span style="color: #881350;">function</span> <span style="color: #003369;">themename_options</span>() {
  <span style="color: #881350;">global</span> <span style="color: #825900;">$options</span>;

    <span style="color: #003369;">add_theme_page</span>(<span style="color: #eb7300;">'Theme Setting'</span>, <span style="color: #eb7300;">'Theme Setting'</span>, <span style="color: #0000ff;">10</span>, <span style="color: #eb7300;">'themename-settings'</span>, <span style="color: #eb7300;">'themename_admin'</span>);
}

<span style="color: #236e25;"><em>//All the code of displaying will be here </em></span><span style="color: #881350;">function</span> <span style="color: #003369;">themename_admin</span>() {
    <span style="color: #881350;">global</span> <span style="color: #825900;">$options</span>;

}

<span style="color: #003369;">add_action</span>(<span style="color: #eb7300;">'admin_menu'</span>, <span style="color: #eb7300;">'themename_options'</span>);

<span style="color: #dd0000;">?&gt;</span></pre>
<p>The <strong>add_theme_page()</strong> function is used to add a page to a add a page to your WP admin. Here it is, this page is your theme setting page. <strong>The third parameter</strong> is included as unique URL to this page. Example with this URL below is the link to a theme setting page:</p>
<pre class="html">http://localhost/wp-admin/themes.php?page=themename-settings</pre>
<p>The <strong>add_action()</strong> function is used to hook function themename_option() and create a menu item in admin menu. You cannot access your theme setting page without this function.</p>
<p>You know what? The menu item that link to this page can be added with two different type. The <strong>add_theme_page()</strong> above will add an item into Theme Menu. You can use this code below to add a separated menu item as another parent menu item.</p>
<p>Replace the <strong>add_theme_page()</strong> by <strong>add_menu_page()</strong> with the same parameters:</p>
<pre class="php">    <span style="color: #003369;">add_menu_page</span>(<span style="color: #eb7300;">'Theme Setting'</span>, <span style="color: #eb7300;">'Theme Setting'</span>, <span style="color: #0000ff;">10</span>, <span style="color: #eb7300;">'themename-settings'</span>, <span style="color: #eb7300;">'themename_admin'</span>);</pre>
<p>Take a look:</p>
<div class="bigimage"><img class="alignnone size-full wp-image-951" title="Menu Item Style for Theme Setting Page" src="http://aext.net/wp-contents/uploads/2009/10/Menu-Item-Style-for-Theme-Setting-Page.jpg" alt="Menu Item Style for Theme Setting Page" width="500" height="357" /></div>
<h3>Complete the setting page code</h3>
<hr />
<p>You need more works to make your setting page run smooth. Now, we will combine all the code together. First code block that we start completing code is option array:</p>
<pre class="php"><em>// theme options </em><span style="color: #825900;">$options</span> = <span style="color: #881350;">array</span>(

  <span style="color: #881350;">array</span>(    
    <span style="color: #eb7300;">"name"</span> =&gt; <span style="color: #eb7300;">"&lt;strong&gt;Homepage Community Entries&lt;/strong&gt;"</span>,
    <span style="color: #eb7300;">"desc"</span> =&gt; <span style="color: #eb7300;">"Select the number of Community entries that should appear on the Index page"</span>,
    <span style="color: #eb7300;">"id"</span> =&gt; <span style="color: #eb7300;">"aext_numcomnews"</span>,
    <span style="color: #eb7300;">"default"</span> =&gt; <span style="color: #eb7300;">"10"</span>),

  <span style="color: #881350;">array</span>(
   <span style="color: #eb7300;">"id"</span> =&gt; <span style="color: #eb7300;">"aext_footer"</span>,
   <span style="color: #eb7300;">"default"</span> =&gt; <span style="color: #eb7300;">""</span>),

);</pre>
<p>In this tutorial, I just use two options to make it easy to look. We have two options above, right? But we just need to focus on the value of <strong>id</strong> of each array, because the code below will get value of <strong>id</strong> and we can identify what option we update by <strong>unique id</strong>.</p>
<pre class="php"><span style="color: #dd0000;">&lt;?php</span>

.....

<span style="color: #881350;">function</span> <span style="color: #003369;">themename_admin</span>() {
    <span style="color: #881350;">global</span> <span style="color: #825900;">$options</span>;
<span style="color: #dd0000;">?&gt;</span>
<span style="color: #881280;">&lt;div </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"wrap"</span><span style="color: #881280;">&gt;</span>
  <span style="color: #881280;">&lt;h2 </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"alignleft"</span><span style="color: #881280;">&gt;</span>Theme Setting<span style="color: #881280;">&lt;/h2&gt;</span>
  <span style="color: #881280;">&lt;br </span><span style="color: #994500;">clear</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"all"</span><span style="color: #881280;"> /&gt;</span>

  <span style="color: #dd0000;">&lt;?php</span>
    <span style="color: #236e25;"><em>//Check if settings saved! </em></span>    <span style="color: #881350;">if</span>( <span style="color: #825900;">$_REQUEST</span>[<span style="color: #eb7300;">'saved'</span>] ) {
  <span style="color: #dd0000;">?&gt;</span>
        <span style="color: #881280;">&lt;div </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"updated fade"</span><span style="color: #881280;">&gt;&lt;p&gt;&lt;strong&gt;</span>Setting Saved<span style="color: #881280;">&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;</span>
  <span style="color: #dd0000;">&lt;?php</span> } <span style="color: #dd0000;">?&gt;</span>

<span style="color: #881280;">&lt;form </span><span style="color: #994500;">method</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"post"</span><span style="color: #994500;">id</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"myForm"</span><span style="color: #881280;">&gt;</span>
<span style="color: #881280;">&lt;div </span><span style="color: #994500;">id</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"poststuff"</span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"metabox-holder"</span><span style="color: #881280;">&gt;</span>

 <span style="color: #881280;">&lt;div </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"stuffbox"</span><span style="color: #881280;">&gt;</span>
  <span style="color: #881280;">&lt;h3&gt;</span>Homepage Setting<span style="color: #881280;">&lt;/h3&gt;</span>
  <span style="color: #881280;">&lt;div </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"inside"</span><span style="color: #881280;">&gt;</span>
    <span style="color: #881280;">&lt;table </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"form-table"</span><span style="color: #994500;">style</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"width: auto"</span><span style="color: #881280;">&gt;</span>
    <span style="color: #dd0000;">&lt;?php</span>
     <span style="color: #881350;">foreach</span>(<span style="color: #825900;">$options</span> <span style="color: #881350;">as</span> <span style="color: #825900;">$value</span>) {
      <span style="color: #881350;">switch</span>( <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>] ) {
        <span style="color: #881350;">case</span> <span style="color: #eb7300;">"aext_numcomnews"</span>: <span style="color: #dd0000;">?&gt;</span>
        <span style="color: #881280;">&lt;tr&gt;</span>
        <span style="color: #881280;">&lt;th </span><span style="color: #994500;">scope</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"row"</span><span style="color: #881280;">&gt;</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'name'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #881280;">&lt;br /&gt;</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'desc'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #881280;">&lt;/th&gt;</span>
        <span style="color: #881280;">&lt;td&gt;</span>
         <span style="color: #881280;">&lt;input </span><span style="color: #994500;">name</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #1a1aa6;">"</span><span style="color: #881280;">                 </span><span style="color: #994500;">id</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #1a1aa6;">"</span><span style="color: #994500;">type</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"text"</span><span style="color: #881280;">                 </span><span style="color: #994500;">value</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #003369;">get_option</span>(<span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>])?<span style="color: #661aa9;">printf</span>(<span style="color: #003369;">get_option</span>(<span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>])): <span style="color: #661aa9;">printf</span>(<span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'default'</span>]) <span style="color: #dd0000;">?&gt;</span><span style="color: #1a1aa6;">"</span><span style="color: #881280;"> /&gt;</span>
        <span style="color: #881280;">&lt;/td&gt;</span>
        <span style="color: #881280;">&lt;/tr&gt;</span>

      <span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">break</span>;
        <span style="color: #881350;">case</span> <span style="color: #eb7300;">"aext_footer"</span>: <span style="color: #dd0000;">?&gt;</span>
        <span style="color: #881280;">&lt;tr&gt;</span>
          <span style="color: #881280;">&lt;th </span><span style="color: #994500;">scope</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"row"</span><span style="color: #881280;">&gt;</span>
            <span style="color: #881280;">&lt;strong&gt;</span>Footer HTML<span style="color: #881280;">&lt;/strong&gt;</span>
            <span style="color: #881280;">&lt;br /&gt;</span>Put some HTML code here. That's helpful if you want to add tracking code ....
          <span style="color: #881280;">&lt;/th&gt;</span>
          <span style="color: #881280;">&lt;td&gt;</span>
            <span style="color: #881280;">&lt;textarea </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"code"</span><span style="color: #994500;">rows</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"4"</span><span style="color: #994500;">cols</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"60"</span><span style="color: #881280;">                         </span><span style="color: #994500;">name</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #1a1aa6;">"</span><span style="color: #881280;">                         </span><span style="color: #994500;">id</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">echo</span> <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>]; <span style="color: #dd0000;">?&gt;</span><span style="color: #1a1aa6;">"</span><span style="color: #881280;">&gt;</span><span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">print</span> <span style="color: #003369;">get_option</span>(<span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>]); <span style="color: #dd0000;">?&gt;</span>
            <span style="color: #881280;">&lt;/textarea&gt;</span>
          <span style="color: #881280;">&lt;/td&gt;</span>
        <span style="color: #881280;">&lt;/tr&gt;</span>

      <span style="color: #dd0000;">&lt;?php</span> <span style="color: #881350;">break</span>;
        }
    }
    <span style="color: #dd0000;">?&gt;</span>
   <span style="color: #881280;">&lt;/table&gt;</span>
  <span style="color: #881280;">&lt;/div&gt;</span>
 <span style="color: #881280;">&lt;/div&gt;</span>  

<span style="color: #881280;">&lt;/div&gt;</span>
<span style="color: #881280;">&lt;input </span><span style="color: #994500;">name</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"theme_save"</span><span style="color: #994500;">type</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"submit"</span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"button-primary"</span><span style="color: #994500;">value</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"Save changes"</span><span style="color: #881280;"> /&gt;</span>
<span style="color: #881280;">&lt;input </span><span style="color: #994500;">type</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"hidden"</span><span style="color: #994500;">name</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"action"</span><span style="color: #994500;">value</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"theme_save"</span><span style="color: #881280;"> /&gt;</span>
<span style="color: #881280;">&lt;/form&gt;</span>

<span style="color: #881280;">&lt;/div&gt;</span>
<span style="color: #dd0000;">&lt;?php</span>
}

.....

<span style="color: #dd0000;">?&gt;</span></pre>
<p>At the top of this block of code above, we check the value of the request <strong>saved</strong>. The text will displays to notify that setting was saved successful. The form will load default value of id: <strong>aext_numcomnews</strong> if there are no value of <strong>aext_numcomnews</strong> in database.</p>
<p>That is the form display. We need to process the value that the form submitted. We do it inside themename_options() function:</p>
<pre class="php"><span style="color: #dd0000;">&lt;?php</span>

<span style="color: #881350;">function</span> <span style="color: #003369;">themename_options</span>() {
  <span style="color: #881350;">global</span> <span style="color: #825900;">$options</span>;

  <span style="color: #881350;">if</span>(<span style="color: #eb7300;">'theme_save'</span>== <span style="color: #825900;">$_REQUEST</span>[<span style="color: #eb7300;">'action'</span>] ) {

    <span style="color: #881350;">foreach</span>(<span style="color: #825900;">$options</span> <span style="color: #881350;">as</span> <span style="color: #825900;">$value</span>) {
     <span style="color: #881350;">if</span>( !<span style="color: #003369;">isset</span>( <span style="color: #825900;">$_REQUEST</span>[ <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>] ] ) ) {  
        <span style="color: #236e25;"><em>//Do nothing </em></span>     } <span style="color: #881350;">else</span> {
        <span style="color: #003369;">update_option</span>( <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>], <span style="color: #661aa9;">stripslashes</span>(<span style="color: #825900;">$_REQUEST</span>[ <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>]])); }
     }

     <span style="color: #881350;">if</span>(<span style="color: #661aa9;">stristr</span>(<span style="color: #825900;">$_SERVER</span>[<span style="color: #eb7300;">'REQUEST_URI'</span>],<span style="color: #eb7300;">'&amp;saved=true'</span>)) {
        <span style="color: #825900;">$location</span> = <span style="color: #825900;">$_SERVER</span>[<span style="color: #eb7300;">'REQUEST_URI'</span>];
     } <span style="color: #881350;">else</span> {
        <span style="color: #825900;">$location</span> = <span style="color: #825900;">$_SERVER</span>[<span style="color: #eb7300;">'REQUEST_URI'</span>] . <span style="color: #eb7300;">"&amp;saved=true"</span>;
     }

     <span style="color: #661aa9;">header</span>(<span style="color: #eb7300;">"Location: </span><span style="color: #c94b16;">$location</span><span style="color: #eb7300;">"</span>);
     <span style="color: #881350;">die</span>;
  }

  <span style="color: #003369;">add_theme_page</span>(<span style="color: #eb7300;">'AEXT Theme Setting'</span>, <span style="color: #eb7300;">'AEXT Theme Setting'</span>, <span style="color: #0000ff;">10</span>, <span style="color: #eb7300;">'aext-settings'</span>, <span style="color: #eb7300;">'aext_admin'</span>);
}

<span style="color: #dd0000;">?&gt;</span></pre>
<p>That function processes the data submitted by <strong>update_option()</strong> with parameter is the value of each <strong>id</strong> was changed. After submit your changes, your all changes will be made in table <strong>wp_options</strong> in your database.</p>
<p>At last, remember to put the line of code here at the end of your <strong>functions.php</strong> file:</p>
<pre class="php"><span style="color: #003369;">add_action</span>(<span style="color: #eb7300;">'admin_menu'</span>, <span style="color: #eb7300;">'themename_options'</span>);</pre>
<p>If you want to rest your current options to default value, simply copy and paste these code next to your current form. The reason is we can not submit two value <strong>theme_save</strong> and <strong>theme_reset</strong> at same time.</p>
<pre class="html"><span style="color: #881280;">&lt;form </span><span style="color: #994500;">method</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"post"</span><span style="color: #881280;">&gt;</span>
    <span style="color: #881280;">&lt;p </span><span style="color: #994500;">class</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"submit"</span><span style="color: #994500;">style</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"border: 0;"</span><span style="color: #881280;">&gt;</span>
       <span style="color: #881280;">&lt;input </span><span style="color: #994500;">name</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"reset"</span><span style="color: #994500;">type</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"submit"</span><span style="color: #994500;">value</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"Reset"</span><span style="color: #881280;"> /&gt;</span>
       <span style="color: #881280;">&lt;input </span><span style="color: #994500;">type</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"hidden"</span><span style="color: #994500;">name</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"action"</span><span style="color: #994500;">value</span><span style="color: #881280;">=</span><span style="color: #1a1aa6;">"theme_reset"</span><span style="color: #881280;"> /&gt;</span>
    <span style="color: #881280;">&lt;/p&gt;</span>
<span style="color: #881280;">&lt;/form&gt;</span></pre>
<p>And edit your theme_options() funtion like this:</p>
<pre class="php">  <span style="color: #881350;">if</span>(<span style="color: #eb7300;">'theme_save'</span>== <span style="color: #825900;">$_REQUEST</span>[<span style="color: #eb7300;">'action'</span>] ) {

    .....

  } <span style="color: #881350;">else</span> <span style="color: #881350;">if</span>(<span style="color: #eb7300;">'theme_reset'</span> == <span style="color: #825900;">$_REQUEST</span>[<span style="color: #eb7300;">'action'</span>] ) {

    <span style="color: #881350;">foreach</span>(<span style="color: #825900;">$options</span> <span style="color: #881350;">as</span> <span style="color: #825900;">$value</span>) {
     <span style="color: #003369;">delete_option</span>( <span style="color: #825900;">$value</span>[<span style="color: #eb7300;">'id'</span>] );
     <span style="color: #825900;">$location</span> = <span style="color: #825900;">$_SERVER</span>[<span style="color: #eb7300;">'REQUEST_URI'</span>] . <span style="color: #eb7300;">"&amp;reset=true"</span>;
    }

    <span style="color: #661aa9;">header</span>(<span style="color: #eb7300;">"Location: </span><span style="color: #c94b16;">$location</span><span style="color: #eb7300;">"</span>);
    <span style="color: #881350;">die</span>;

  }</pre>
<h3>Get your options in your theme files</h3>
<hr />
<p>It&#8217;s as easy as the code at the top of this entry. Because all of your options are stored in database, we will get values for a named option from the options database table. If the desired option does not exist, return value is <strong>FASLE</strong>.</p>
<p>In my index.php file:</p>
<pre class="php">
......

<span style="color: #dd0000;">&lt;?php</span> 

    <span style="color: #825900;">$numcomnews</span> = <span style="color: #003369;">get_option</span>(<span style="color: #eb7300;">'aext_numcomnews'</span>);

    <span style="color: #003369;">query_posts</span>(<span style="color: #eb7300;">"category_name=Community News&amp;showposts=</span><span style="color: #c94b16;">$numcomnews</span><span style="color: #eb7300;">"</span>);

    <span style="color: #881350;">if</span>(<span style="color: #003369;">have_posts</span>()) :

    <span style="color: #236e25;"><em>//Displaying posts </em></span>    
    <span style="color: #881350;">endif</span>;

<span style="color: #dd0000;">?&gt;</span>

......</pre>
<h3>What&#8217;s up?</h3>
<hr />
<p>The completed code is attached in this post, you can download it for use later. However, I suggest that you follow step by step to help you get all what I want to say. This tutorial comes along with only two options, you can add more options to customize your own wordpress template. Although these code is working, maybe I am doing something wrong. Feel free to comment, I&#8217;ll really appreciate all you give to me!</p>
<div class="txtad-cont"></div>
]]></content:encoded>
			<wfw:commentRss>http://aext.net/2009/10/wordpress-theme-design-with-options-adminstration/feed/</wfw:commentRss>
		<slash:comments>76</slash:comments>
		</item>
	</channel>
</rss>

