<?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>WPShout.com &#187; Theme Development</title> <atom:link href="http://wpshout.com/category/development/feed/" rel="self" type="application/rss+xml" /><link>http://wpshout.com</link> <description>WordPress Tutorials</description> <lastBuildDate>Wed, 01 Feb 2012 21:03:25 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>Submit WordPress Posts From The Frontend</title><link>http://wpshout.com/wordpress-submit-posts-from-frontend/</link> <comments>http://wpshout.com/wordpress-submit-posts-from-frontend/#comments</comments> <pubDate>Wed, 18 Aug 2010 14:04:03 +0000</pubDate> <dc:creator>Jared</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Theme Development]]></category> <category><![CDATA[Advanced Uses of WordPress]]></category> <category><![CDATA[Custom Post Types]]></category> <category><![CDATA[Post Form]]></category><guid isPermaLink="false">http://wpshout.com/?p=3222</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/wordpress-submit-posts-from-frontend/">Submit WordPress Posts From The Frontend</a></p></p><p>If your looking to make adding new posts without having to log into the WordPress dashboard, or maybe to allow your visitors a way to submit some kind of content of their own, then here's a way you can create a new post form and display it on a custom page template.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/wordpress-submit-posts-from-frontend/">Submit WordPress Posts From The Frontend</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/wordpress-submit-posts-from-frontend/">Submit WordPress Posts From The Frontend</a></p></p><p><em>This is a guest post by Jared Williams of <a href="http://new2wp.com">New2WP.com</a></em></p><p>If you&#8217;re looking to make adding new posts without having to log into the WordPress dashboard, or maybe to allow your visitors a way to submit some kind of content of their own, then here&#8217;s a way you can create a new post form and display it on a custom page template.</p><p>In order to write a new post in WordPress you have to do a number of steps just to get started. First you must login to get to the dashboard, then go to posts, and then add new post. That&#8217;s a total of 3 page refreshes with the need to type your name and password as well, and that&#8217;s just to get to the post write page. Yeah you could use the quick post widget on the dashboard page, but then you still have to go to edit the post if you want to add a category or some tags plus any other things you may use in your post.</p><p>If you have members of your site that join so they can submit some kind of content or another, it can be even better for them as well to not have to go through all the steps it takes in submitting a new post. Plus this can be used for making a new post form for custom post types, too.</p><p>This custom post form is something I developed after trying all the form plugins I could find, including the more well known TDOForms, and Gravity forms plugins which both are quite capable of doing this but are more than I needed. I&#8217;ve even hacked, dissected, and attacked the Prologue and P2 themes since they are Twitter-style themes that have a post form right on the main page. I mean I ripped them both apart, and slaughtered the code in them to death, and failed. Prologue couldn&#8217;t do what I wanted, and the P2 theme code is so intertwined within itself it was just too much of a pain to undo the knot of code it consists of.</p><h2>1. The Form</h2><p>First we will set up the basic form which you can use to enter in the information to submit new posts.</p><pre>&lt;!-- New Post Form --&gt;

&lt;div id="postbox"&gt;

&lt;form id="new_post" name="new_post" method="post" action=""&gt;

&lt;p&gt;&lt;label for="title"&gt;Title&lt;/label&gt;&lt;br /&gt;

&lt;input type="text" id="title" value="" tabindex="1" size="20" name="title" /&gt;

&lt;/p&gt;

&lt;p&gt;&lt;label for="description"&gt;Description&lt;/label&gt;&lt;br /&gt;

&lt;textarea id="description" tabindex="3" name="description" cols="50" rows="6"&gt;&lt;/textarea&gt;

&lt;/p&gt;

&lt;p&gt;&lt;?php wp_dropdown_categories( 'show_option_none=Category&amp;tab_index=4&amp;taxonomy=category' ); ?&gt;&lt;/p&gt;

&lt;p&gt;&lt;label for="post_tags"&gt;Tags&lt;/label&gt;

&lt;input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /&gt;&lt;/p&gt;

&lt;p align="right"&gt;&lt;input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /&gt;&lt;/p&gt;

&lt;input type="hidden" name="post_type" id="post_type" value="post" /&gt;

&lt;input type="hidden" name="action" value="post" /&gt;

&lt;?php wp_nonce_field( 'new-post' ); ?&gt;

&lt;/form&gt;

&lt;/div&gt;

&lt;!--// New Post Form --&gt;</pre><p>There&#8217;s nothing special with this form really. The only thing is the wp_dropdown_categories() function, which creates the list of categories you can select from. You can <a href="http://codex.wordpress.org/Function_Reference/wp_dropdown_categories">learn more about this function here</a>. Everything else you enter into the form will automatically create a new entry, including tags. Make sure no matter what you do, always include the wp_nonce_field(), for <a href="http://wpshout.com/10-practical-wordpress-security-tips/"target="_blank"title="WordPress Security Tips" >security</a> reasons.</p><h2>2. The PHP for Processing the Form</h2><p>Here is where the fun part begins. This is the PHP which you need to process and submit the form information.</p><pre>&lt;?
if( 'POST' == $_SERVER['REQUEST_METHOD'] &amp;&amp; !empty( $_POST['action'] )) {

	// Do some minor form validation to make sure there is content
	if (isset ($_POST['title'])) {
		$title =  $_POST['title'];
	} else {
		echo 'Please enter a title';
	}
	if (isset ($_POST['description'])) {
		$description = $_POST['description'];
	} else {
		echo 'Please enter the content';
	}
	$tags = $_POST['post_tags'];

	// Add the content of the form to $post as an array
	$post = array(
		'post_title'	=&gt; $title,
		'post_content'	=&gt; $description,
		'post_category'	=&gt; $_POST['cat'],  // Usable for custom taxonomies too
		'tags_input'	=&gt; $tags,
		'post_status'	=&gt; 'publish',			// Choose: publish, preview, future, etc.
		'post_type'	=&gt; $_POST['post_type']  // Use a custom post type if you want to
	);
	wp_insert_post($post);  // Pass  the value of $post to WordPress the insert function
							// http://codex.wordpress.org/Function_Reference/wp_insert_post
	wp_redirect( home_url() );
} // end IF

// Do the wp_insert_post action to insert it
do_action('wp_insert_post', 'wp_insert_post'); 

?&gt;</pre><p>Let&#8217;s go over this.</p><p>The first line checks if a post has been submitted, and if the action is not empty. You could do this check a number of ways, this is just how I&#8217;ve done it:<br /> if( &#8216;POST&#8217; == $_SERVER['REQUEST_METHOD'] &amp;&amp; !empty( $_POST['action'] )) {</p><p>The second part is a basic form validation that checks to see if the title and description fields are set, and if so set the values to the variables $title and $description. You may want to check that each of the fields are set this way but I am just showing as an example.</p><p>Then, I set up a variable called $post, which is an array of values from the form fields.</p><ul><li>post_title = $title like we set above using the validation</li><li>post_content = $description as we set</li><li>post_category = the category that was selected</li><li>tags_input = the tags</li><li>post_status = publish, future or draft. Whatever you want to set it to</li><li>post_type = post, page, or if you have set up a custom post type you can use that instead</li></ul><p>To insert the new post information you can use the function <a href="http://codex.wordpress.org/Function_Reference/wp_insert_post">wp_insert_post()</a> and passing the $post variable to it. This is all of course, only if the form has been submitted which is why we put all this within the &#8216;if&#8217; statement.</p><p><strong>Update:</strong> I&#8217;ve added the function wp_redirect() after the wp_insert_post() function, to fix the redirect to a 404 page. You can change the location by passing the function an argument. For example: wp_redirect( &#8216;/some-page/&#8217;) or wp_redirect( home_url() ).</p><p>Close the IF statement and then add the action. The line do_action(&#8216;wp_insert_post&#8217;, &#8216;wp_insert_post&#8217;); will add the wp_insert_post hook, with the wp_insert_post from the if statement as the callback, thereby adding the $post variable with all it&#8217;s information to the function. Without this line the post will not be submitted and your form will be useless.</p><p>I will leave the CSS up to you since I am not here to make your form look pretty, just work. Besides, everyone styles things differently anyways.</p><p>You can embed this code in a <a href="http://codex.wordpress.org/Pages#Templates_by_page-ID_or_page-Slug">custom page template</a>, say for example: page-submit.php. Copy the code from page.php and paste it in your custom template. You can create custom pate templates using page-<strong>slug</strong>.php or page-<strong>id</strong>.php. I find making <a href="http://new2wp.com/noob/wordpress-custom-templates-the-easy-and-most-logical-method/">custom templates this way 100 times better</a> than using the old way, which involves assigning the page a specific template in the page attributes.</p><p>Make sure that you create a new page in the WordPress dashboard, and that your page slug or page id match the name of your template file (ie: page-submit.php &#8211; page slug = submit). This new page you create will automatically use the custom template you make, so there is no need to do anything else. You can enter content into the page if you choose to of course, but as long as the custom template includes the new post form, either above or below the_content() function you are good to go.</p><p><a href="http://new2wp.com/labs/downloads/New_Post_Forn_by-Jared_New2WP.txt">Download this code here</a></p><p>If you have any questions about this, or can&#8217;t get it to work let me know in the comments.</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/wordpress-submit-posts-from-frontend/">Submit WordPress Posts From The Frontend</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/wordpress-submit-posts-from-frontend/feed/</wfw:commentRss> <slash:comments>102</slash:comments> </item> <item><title>WordPress as a Review Site and Podcasting Site: Advanced Uses of WordPress</title><link>http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/</link> <comments>http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/#comments</comments> <pubDate>Fri, 06 Nov 2009 12:00:02 +0000</pubDate> <dc:creator>Alex Denning</dc:creator> <category><![CDATA[Advanced Uses of WordPress]]></category><guid isPermaLink="false">http://wpshout.com/?p=1584</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/">WordPress as a Review Site and Podcasting Site: Advanced Uses of WordPress</a></p></p><p>Create a review and podcasting site with WordPress.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/">WordPress as a Review Site and Podcasting Site: Advanced Uses of WordPress</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/">WordPress as a Review Site and Podcasting Site: Advanced Uses of WordPress</a></p></p><div>Continuing [ad], today we&#8217;re going to be looking into using WordPress as review and podcasting site.</div><ol><li>Day 1: <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Tumblelog</a></li><li>Day 2: <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Review Site and Podcasting Site</a></li><li>Day 3: <a href="http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/">WordPress as a Social Network and Twitter clone</a></li></ol><p>You should never say &#8220;oh, you can&#8217;t do that in WordPress&#8221;. Because you probably can. That&#8217;s the beauty of the platform &#8211; at face value, yes, it is a blogging platform, but be a bit creative and you&#8217;ve got yourself a full blown CMS.</p><h2 style="font-size: 1.5em;">WordPress as a review/podcasting site</h2><p><img style="border: 0px initial initial;" title="Nometet" src="http://nometech.com/wpshout.com/wp-content/uploads/images/it3xeg.png" alt="" width="590" /></p><p>Above is a picture of <a href="http://nometet.com">Nometet.com</a>, a games reviews site which also has a sporadically posted podcast. Nometet uses a gallery theme to great effect &#8211; each post has its own image (set through a custom field) which gets auto resized to create a lovely gallery. But where the &#8216;review functionality&#8217; really kicks in is with the <a href="http://www.channel-ai.com/blog/plugins/star-rating/">star ratings for reviews</a> plugin. Each review has a star rating &#8211; simple enough, but this star rating, along with other bits of data, is sortable through a rather nice <a href="http://nometet.com/reviews/">jQuery table</a>:</p><p><img style="border: 0px initial initial;" title="Reviews in WordPress" src="http://nometech.com/wpshout.com/wp-content/uploads/images/cgy4j4.png" alt="" width="510" height="428" /></p><p>As for podcasting, look no further than the excellent <a href="http://www.mightyseek.com/podpress/">podPress plugin</a>. It offers you a ton of options for iTunes integration, includes a flash player and various other bits and bobs:</p><p><img style="border: 0px initial initial;" title="Podcasting with WordPress" src="http://nometech.com/wpshout.com/wp-content/uploads/images/14r5uc.png" alt="" width="486" height="66" /></p><h2 style="font-size: 1.5em;">WordPress as a CMS</h2><p>We&#8217;ve been building up to using <a href="http://wpshout.com/wordpress-as-a-cms/"target="_blank"title="WordPress As A CMS" >WordPress as a CMS</a>. With the plugins mentioned above, you can really easily use WordPress for any number of uses. However, using it on a client project as a CMS? Use custom fields to your advantage and you&#8217;ll be fine &#8211; as I&#8217;ve said before, custom fields are what turns WordPress <em>into</em> a CMS &#8211; you can use them to store all sorts of information. Here&#8217;s an example. I want to display the place where an article was written, and if I haven&#8217;t entered that I&#8217;ll just display the date. Using custom fields, that&#8217;s easy:</p><pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;"><code>&lt;?php
$Place = get_post_custom_values("Place");
if ( is_array($Place) ) { ?&gt;
Plublished in: &lt;?php echo get_post_meta($post-&gt;ID, "Place", true); ?&gt;
&lt;?php }	else { ?&gt;
Published on &lt;?php the_time('n/d/y'); ?&gt;
&lt;?php }	?&gt;</code></pre><p>Just create a custom field &#8216;Place&#8217; and enter the place where the article was written and it&#8217;ll appear. If no custom field exists, then the date the post was published on gets displayed instead.</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/">WordPress as a Review Site and Podcasting Site: Advanced Uses of WordPress</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>WordPress as a Social Network and Twitter clone: Advanced Uses of WordPress</title><link>http://wpshout.com/wordpress-as-a-social-network-and-twitter-clone-advanced-uses-of-wordpress/</link> <comments>http://wpshout.com/wordpress-as-a-social-network-and-twitter-clone-advanced-uses-of-wordpress/#comments</comments> <pubDate>Wed, 04 Nov 2009 17:00:05 +0000</pubDate> <dc:creator>Alex Denning</dc:creator> <category><![CDATA[Advanced Uses of WordPress]]></category><guid isPermaLink="false">http://wpshout.com/?p=1241</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/wordpress-as-a-social-network-and-twitter-clone-advanced-uses-of-wordpress/">WordPress as a Social Network and Twitter clone: Advanced Uses of WordPress</a></p></p><p>Using WordPress as a social network and Twitter clone has just got a heck of a lot easier! Day three of Advanced Uses of WordPress looks at just that.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/wordpress-as-a-social-network-and-twitter-clone-advanced-uses-of-wordpress/">WordPress as a Social Network and Twitter clone: Advanced Uses of WordPress</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/wordpress-as-a-social-network-and-twitter-clone-advanced-uses-of-wordpress/">WordPress as a Social Network and Twitter clone: Advanced Uses of WordPress</a></p></p><div>Day three of [ad] continues, with a look at WordPress as a social network and Twitter site.<a href="http://wpshout.wpcdn.com/media/2009/10/ad-wp-day-2.jpg"><img class="size-full wp-image-1230 alignright" title="ad-wp-day-2" src="http://wpshout.wpcdn.com/media/2009/10/ad-wp-day-2.jpg" alt="ad-wp-day-2" /></a></div><ol><li>Day 1: <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Tumblelog</a></li><li>Day 2: <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Review Site and Podcasting Site</a></li><li>Day 3: <a href="http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/">WordPress as a Social Network and Twitter clone</a></li></ol><p>As I mentioned the other day,  the multi-user version of WordPress is called <a href="http://mu.wordpress.org/">WordPressMU</a>. <a href="http://wpshout.com/getting-started-with-wpmu-and-buddypress-part-1-installing-wpmu/">Installing WPMU</a> is something I&#8217;ve covered before here on <a href="http://wpshout.com">WPShout</a>, so check that out for details how to install it. With WordPress MU installed, there&#8217;s an excellent plugin you can add called BuddyPress. Again, I&#8217;ve written about <a href="http://wpshout.com/getting-started-with-wpmu-and-buddypress-part-2-installing-buddypress/">how to install BuddyPress</a> and <a href="http://wpshout.com/getting-started-with-wpmu-and-buddypress-part-3-getting-to-grips-with-buddypress/">get to grips with it</a> before, so check out <a href="http://wpshout.com/category/development/wordpress-mu/">those tutuorials</a>.</p><p>Whilst we&#8217;re not <em>strictly</em> using WordPress here, it&#8217;s close enough, and the possibilities for expansion are huge &#8211; just take a look at the <a href="http://www.telegraph.co.uk/comment/blogs/">Telegraph&#8217;s blogs</a> &#8211; all run on WordPress MU.</p><pre><code>&lt;meta name="generator" content="WordPress 2.7.1" /&gt; </code></pre><p>Interestingly, though, they&#8217;re only running 2.7.1!</p><h2>Making a Twitter clone with WordPress</h2><p><a href="http://nometech.com/wpshout.com/wp-content/uploads/images/25zjh7.png"><img class="alignnone" title="P2" src="http://nometech.com/wpshout.com/wp-content/uploads/images/25zjh7.png" alt="" width="590" /></a></p><p>Twitter clones are all the range these days, and, thankfully, there&#8217;s a WordPress theme that does the job of Twitter clone. <a href="http://wordpress.org/extend/themes/p2">Prologue</a>, or P2, allows you to make your own Twitter clone on <em>any</em> WordPress install &#8211; just set up a new install of WordPress, click &#8216;Add New Themes&#8217;, do a search for P2, install it and activate it. And you&#8217;re done.</p><p>With P2 installed, the subscribe to comments plugin is pretty darn useful and you might want to restrict access to only those who are logged in.</p><h2>Concluding</h2><p>Just a (comparatively) quick post today and not a mention of custom fields! It would have been longer, but it occurred to me halfway through writing the post that I&#8217;d already written what I wanted to say! Join us tomorrow to find out how to use WordPress as a review site.</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/wordpress-as-a-social-network-and-twitter-clone-advanced-uses-of-wordpress/">WordPress as a Social Network and Twitter clone: Advanced Uses of WordPress</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/wordpress-as-a-social-network-and-twitter-clone-advanced-uses-of-wordpress/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>WordPress as a Tumblelog, CMS: Advanced Uses of WordPress</title><link>http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/</link> <comments>http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/#comments</comments> <pubDate>Tue, 03 Nov 2009 17:00:21 +0000</pubDate> <dc:creator>Alex Denning</dc:creator> <category><![CDATA[Advanced Uses of WordPress]]></category><guid isPermaLink="false">http://wpshout.com/?p=1223</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Tumblelog, CMS: Advanced Uses of WordPress</a></p></p><p>Day one of "Advanced Uses of WordPress" looks at using WordPress to create a Tumblelog using custom fields.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Tumblelog, CMS: Advanced Uses of WordPress</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Tumblelog, CMS: Advanced Uses of WordPress</a></p></p><div>Kicking off this month&#8217;s series [ad], today we&#8217;ll be looking at WordPress as an advanced blogging platform <em>and</em> a Tumblelog.</div><div><a href="http://wpshout.wpcdn.com/media/2009/11/ad-wp-day-2.jpg"><img class="size-full wp-image-1598 alignright" title="ad-wp-day-2" src="http://wpshout.wpcdn.com/media/2009/11/ad-wp-day-2.jpg" alt="ad-wp-day-2" width="250" height="250" /></a></div><ol><li>Day 1: <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Tumblelog</a></li><li>Day 2: <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Review Site and Podcasting Site</a></li><li>Day 3: <a href="http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/">WordPress as a Social Network and Twitter clone</a></li></ol><p>You should never say &#8220;oh, you can&#8217;t do that in WordPress&#8221;. Because you probably can. That&#8217;s the beauty of the platform &#8211; at face value, yes, it is a blogging platform, but be a bit creative and you&#8217;ve got yourself a full blown CMS.</p><h2>WordPress as an advanced blogging platform</h2><p><a href="http://nometech.com/wpshout.com/wp-content/uploads/images/g6xzmi.png"><img class="alignnone" title="WordPress as a CMS" src="http://nometech.com/wpshout.com/wp-content/uploads/images/g6xzmi.png" alt="" width="590" /></a></p><p>The image above is a screen of BinaryMoon.co.uk, Ben Gillbanks&#8217; blog. It&#8217;s powered by WordPress and look at it! Popular posts on a scrolling, jQuerified block, recent posts from various categories down the sidebar, with one post <em>only</em> having an excerpt. It&#8217;s a brilliant example of how you can use WordPress as an <em>advanced</em> blogging platform; a good knowledge of the <a href="http://wpshout.com/wordpress-template-file-hierarchy-explained/">template hierarchy</a>, the <a href="http://wpshout.com/a-beginners-guide-to-wordpress-theme-development/">basics of WordPress development</a> and some design skills and you&#8217;re effectively there. Sites such as Ben&#8217;s prove just how versatile WordPress is as a blogging platform. Speaking of which&#8230;</p><h2>WordPress as a Tumblelog</h2><p><a href="http://nometech.com/wpshout.com/wp-content/uploads/images/av3svp.png"><img class="alignnone" title="Tumblelog in WordPress" src="http://nometech.com/wpshout.com/wp-content/uploads/images/av3svp.png" alt="" width="590" /></a></p><p>Microblogging is yet another thing that WordPress is brilliantly suited to. To prove the point, I&#8217;ve just very quickly created a <a href="http://wpshout.com/free-wordpress-magazineframeworkbloggytech-blog-theme-biblioteca/">Biblioteca</a> child theme which acts as a Tumblelog: using custom fields and custom write panels I&#8217;ve been able to set up a homepage where the latest posts get displayed, in Tumblelog form. However, there&#8217;s a bonus &#8211; again, using  just custom fields, you can post links! It&#8217;s all very clever &#8211; the image above is the actual theme &#8211; I just took <a href="http://wpshout.com/free-wordpress-magazineframeworkbloggytech-blog-theme-biblioteca/">Biblioteca</a>, created a child theme of it, got rid of the sidebar and made it single column and I was left with a decent Tumble-like design. Taking it further though, the first post &#8211; WPShout &#8211; is actually a link to <a href="http://wpshout.com">WPShout</a>. How? Using <a href="http://wpshout.com/free-wordpress-magazineframeworkbloggytech-blog-theme-biblioteca/">Biblioteca</a>&#8216;s<a href="http://wpshout.com/create-an-in-post-theme-options-meta-box-in-wordpress/"> custom write meta box thingys</a> (I still don&#8217;t know the technical term!) I can create a new post which contains the link and then under &#8216;title&#8217; type in the link URL:</p><p><a href="http://nometech.com/wpshout.com/wp-content/uploads/images/qj56sz.png"><img class="alignnone" title="Custom write panels" src="http://nometech.com/wpshout.com/wp-content/uploads/images/qj56sz.png" alt="" width="498" height="181" /></a></p><p>And to integrate that onto the homepage, I can use the following:</p><pre><code>&lt;?php
$Post = get_post_custom_values("Title");
if ( is_array($Post) ) { ?&gt;
&lt;h2 class="posttitle"&gt;&lt;?php echo get_post_meta($post-&gt;ID, "Title", true); ?&gt;&lt;/h2&gt;
&lt;?php }	else { ?&gt;
&lt;h2 class="posttitle"&gt;&lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php the_title();?&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;?php }	?&gt;</code></pre><p>The clever bit here is that for normal blog posts, just leave the field blank and the title gets displayed. It&#8217;s really easy to create something like this so go on! Do it!</p><h2>Concluding</h2><p>Throughout this week I&#8217;m going to bang on about custom fields, which I make no apology for; they&#8217;re a brilliant way of storing extra information about posts and you can&#8217;t ignore them! Join us on Wednesday to find out how to use WordPress as a social network with Twitter-like functionality.</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Tumblelog, CMS: Advanced Uses of WordPress</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Advanced Uses of WordPress</title><link>http://wpshout.com/advanced-uses-of-wordpress/</link> <comments>http://wpshout.com/advanced-uses-of-wordpress/#comments</comments> <pubDate>Mon, 02 Nov 2009 17:00:50 +0000</pubDate> <dc:creator>Alex Denning</dc:creator> <category><![CDATA[Advanced Uses of WordPress]]></category><guid isPermaLink="false">http://wpshout.com/?p=1213</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/advanced-uses-of-wordpress/">Advanced Uses of WordPress</a></p></p><p>WordPress as a CMS, social network, Twitter site, eCommerce and gallery? WPShout runs through how to achieve all of those with "Advanced Uses of WordPress" week.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/advanced-uses-of-wordpress/">Advanced Uses of WordPress</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/advanced-uses-of-wordpress/">Advanced Uses of WordPress</a></p></p><p><a href="http://wpshout.com/wp-content/uploads/2009/08/ad-wp-day-1.jpg"><img class="alignright size-full wp-image-1217" title="ad-wp-day-1" src="http://wpshout.com/wp-content/uploads/2009/08/ad-wp-day-1.jpg" alt="ad-wp-day-1" width="250" height="250" /></a></p><p>This is the third of <a href="http://wpshout.com">WPShout</a>&#8216;s themed weeks, this time with the foucs being on advanced uses of WordPress. Whilst WordPress is traditionally a blogging platform, that is certainly not the only use for it. Throughout this week we&#8217;re going to be looking at [ad], with the table of contents as follows:</p><ol><li><strong>Day 1: </strong><a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/"><strong>WordPress as a Tumblelog</strong></a></li><li>Day 2: <a href="http://wpshout.com/advanced-uses-of-wordpress-cms-tumblelogs-reviews-and-podcasting/">WordPress as a Review Site and Podcasting Site</a></li><li>Day 3: <a href="http://wpshout.com/wordpress-as-a-review-site-and-podcasting-site-advanced-uses-of-wordpress/">WordPress as a Social Network and Twitter clone</a></li></ol><p>(if the links don&#8217;t work, that means coming soon!)</p><h2>The introductory bit</h2><p>WordPress is a great blogging platform. A simple, easy to use backend and scope for development with plugins and themes. WordPress is also a brilliant CMS. More and more, WordPress is being used for all kinds of different sites; the power of <a href="http://wpshout.com/category/themes/">WordPress themes</a> and frameworks, such as <a href="http://wpshout.com/free-wordpress-magazineframeworkbloggytech-blog-theme-biblioteca/">Biblioteca</a>, make WordPress a really powerful CMS. You&#8217;ve just got the think outside the box. You want to make a site with a large featured post, explaining about a product, with links to buy the product and recent blog posts on the sidebar? Easy. In WordPress you could use widgets, create a category for the featured product and display the post with the info on it. You could use custom fields, harcode it with a custom page template&#8230; the options are endless. That&#8217;s the point I&#8217;m going to attempt to convey this week; you want to do <em>literally anything</em>? WordPress can do it for you.</p><h2>Advanced Uses of WordPress&#8217; Reading List</h2><p>There are a couple of posts here on <a href="http://wpshout.com">WPShout</a> that you should read before delving into the series to give you a solid understanding of all the jargon I&#8217;m using and all the options available to you:</p><ul><li><a href="http://wpshout.com/category/themes/a-beginners-guide-to-wordpress-theme-development-themes/ ">"A Beginner Guide To WordPress Theme Development"</a></li><li><a href="http://wpshout.com/10-awesome-things-to-do-with-wordpress-custom-fields/">10 Awesome Things to do with WordPress&#8217; Custom Fields</a></li><li><a href="http://wpshout.com/create-the-perfect-widget-ready-wordpress-theme/">Creating the perfect widget ready WordPress theme</a></li><li><a style="text-decoration: none;" href="http://wpshout.com/wordpress-template-file-hierarchy-explained/">WordPress&#8217; Template File Hierarchy Explained</a></li></ul><p>With those posts read and understood, you&#8217;ll be in pretty good shape for the rest of the week&#8217;s post. Make sure you <a href="http://feeds2.feedburner.com/nometech">subscribe by RSS</a> to catch the full week&#8217;s postings.</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/advanced-uses-of-wordpress/">Advanced Uses of WordPress</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/advanced-uses-of-wordpress/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Create An Advanced Theme Options Page in WordPress: Day 4</title><link>http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-4/</link> <comments>http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-4/#comments</comments> <pubDate>Thu, 08 Oct 2009 15:00:54 +0000</pubDate> <dc:creator>Alex Denning</dc:creator> <category><![CDATA[Theme Options Page]]></category><guid isPermaLink="false">http://wpshout.com/?p=1430</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-4/">Create An Advanced Theme Options Page in WordPress: Day 4</a></p></p><p>Day 4 of "Create an Awesome Theme Options Page in WordPress" finishes off the theme options page.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-4/">Create An Advanced Theme Options Page in WordPress: Day 4</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-4/">Create An Advanced Theme Options Page in WordPress: Day 4</a></p></p><p>Day 4 of <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Creating an Advanced Theme Options Page in WordPress</a> is here!</p><li><a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Day 1: Introduction</a></li><li><a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/">Day 2: Creating the different options</a></li><li><a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-3/">Day 3: Styling the options page</a></li><li><strong>Day 4: Implementing the options into a theme</strong></li><p>Today comes the exciting implementation of our options page that we created yesterday. The first thing to do is to create a new file called get-theme-options.php and save it with your theme files. In this file paste the following:</p><pre><code>&lt;?php
//allows the theme to get info from the theme options page
global $options;
foreach ($options as $value) {
    if (get_option( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; }
    else { $$value['id'] = get_option( $value['id'] ); }
    }
?&gt;</code></pre><p>What it does is it allows us to reference the options we’ve selected in the backend. We need to include it in every file that you want to use theme options, which we can do with the following:</p><pre><code>&lt;?php include (TEMPLATEPATH.'/get-theme-options.php'); ?&gt;
</code></pre><h2>Implementing Feedburner</h2><p>The very first option on our options page was the Feedburner address, where users could input their Feedburner URL and it’ll become the RSS feed. With get-theme-options at the top of our header.php file, to get the contents of the Feedburner field from the options page, it’s just a simple <em>echo</em>. At this point you’ll need the shortname you entered in part two and combine this with the ID for the Feedburner, in our example with a shortname of blt and the feedburner ID of _feedburner, that makes blt_feedburner. Combine <em>that</em> with an echo and you get this:</p><pre><code>&lt;?php echo $blt_feedburner;?&gt;
</code></pre><p>Add this to the RSS link in the header and you’ll get something like this:</p><pre><code>&lt;link rel="alternate" type="application/rss+xml" title="&lt;?php bloginfo('name'); ?&gt;" href="&lt;?php echo $blt_feedburner; ?&gt;" /&gt;
</code></pre><p>The same applies to the other text boxes -</p><pre><code>&lt;?php echo $[shortname][ID]; ?&gt;</code></pre><p>. For example, for the Analytics code, you’d implement it like so</p><pre><code> &lt;?php echo $blt_analytics; ?&gt;</code></pre><p>, replacing ‘blt’ with the shortname you selected.</p><h2>Changing the layout</h2><p>The next thing we wanted to let users do was enable/disable certain features, with the first option being change the layout. To be able to do this you’ll need to have two (or more) stylesheets, with the different layouts in them. Our example had three layouts to choose from – standard, widened content area and three columns. I’ve created three separate stylesheets, two-column.css, two-column-wide.css and three-column.css. These have been uploaded to /mytheme/css/. With that done, next step is to open up your header.php file and find where the stylesheet is referenced. Below that, with get-theme-options included, copy and paste the following, changing the shortname and ID if necessary:</p><pre><code>&lt;?php if ($blt_three_column == "true") {?&gt;

&lt;link rel="stylesheet" href="&lt;?php bloginfo('template_url'); ?&gt;/css/three-column.css" type="text/css" media="screen,projection" /&gt;

&lt;?php }?&gt;

&lt;?php if ($blt_two_column == "true") {?&gt;

&lt;link rel="stylesheet" href="&lt;?php bloginfo('template_url'); ?&gt;/css/two-column.css" media="screen,projection" /&gt;

&lt;?php }?&gt;

&lt;?php if ($blt_two_column_wide == "true") {?&gt;

&lt;link rel="stylesheet" href="&lt;?php bloginfo('template_url'); ?&gt;/css/two-column-wide.css" type="text/css" media="screen,projection" /&gt;

&lt;?php }?&gt;</code></pre><p>Essentially all we’re doing here is saying <em>if checkbox x is true, do this:</em>.</p><h2>implementing checkboxes: show and hide</h2><p>The same principal applies to showing and hiding ‘stuff’: to hide ‘Homepage Area 1’ I can do so with the following:</p><pre><code>&lt;?php //make sure you include get-theme-options

if ($blt_homepage_area_1 == "true") {?&gt;

&lt;!—homepage area one here --&gt;

&lt;?php }?&gt;

And that is all there is to it! You can obviously repeat the principal, so for ‘Homepage Area 2’ you’d need:

&lt;?php //make sure you include get-theme-options

if ($blt_homepage_area_2 == "true") {?&gt;

&lt;!—homepage area two here --&gt;

&lt;?php }?&gt;

The other option you’ve got is if a checkbox is unticked; just change true to false:

&lt;?php //make sure you include get-theme-options

if ($blt_homepage_area_2 == "false") {?&gt;

&lt;!—homepage area two here --&gt;

&lt;?php }?&gt;</code></pre><h2>Concluding</h2><p>And with that, we’ve finished implementing all the different options we created – now spend the next five minutes enabling and disabling! We’ve also finished the week’s series, but with still a day to go, not to worry; tomorrow we&#8217;ll be wrapping up. See you then!</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-4/">Create An Advanced Theme Options Page in WordPress: Day 4</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-4/feed/</wfw:commentRss> <slash:comments>80</slash:comments> </item> <item><title>Create An Advanced Theme Options Page in WordPress: Day 3</title><link>http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-3/</link> <comments>http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-3/#comments</comments> <pubDate>Wed, 07 Oct 2009 15:00:04 +0000</pubDate> <dc:creator>Alex Denning</dc:creator> <category><![CDATA[Theme Options Page]]></category><guid isPermaLink="false">http://wpshout.com/?p=1319</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-3/">Create An Advanced Theme Options Page in WordPress: Day 3</a></p></p><p>Day three of "Create an advanced theme options page in WordPress" styles the options page.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-3/">Create An Advanced Theme Options Page in WordPress: Day 3</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-3/">Create An Advanced Theme Options Page in WordPress: Day 3</a></p></p><p>Day three of <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Creating an Advanced Theme Options Page in WordPress</a> is here! Today we’ll be taking the options we made yesterday, styling them and creating the actual page that displays them in the WordPress backend.</p><li><a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Day 1: Introduction</a></li><li><a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/">Day 2: Creating the different options</a></li><li><strong>Day 3: Styling the options page</strong></li><li>Day 4: Implementing the options into a theme</li><p><a href="http://wpshout.com/dowloads/theme-options-day-3.txt"><img class="alignnone size-full wp-image-1313" title="download-2" src="http://wpshout.com/wp-content/uploads/2009/10/download-2.jpg" alt="download-2" width="590" height="250" /></a></p><h2>Creating the options page</h2><p>The first thing we’re going to do today is create the actual page that shows the options, which we can do with the following code, pasted straight after where we left off yesterday, in the functions.php file:</p><pre><code>	);

function mytheme_add_admin() {

    global $themename, $shortname, $options;

    if ( $_GET['page'] == basename(__FILE__) ) {

        if ( 'save' == $_REQUEST['action'] ) {

                foreach ($options as $value) {
                    update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }

                foreach ($options as $value) {
                    if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }

                header("Location: themes.php?page=theme-options.php&amp;saved=true");
                die;

        } else if( 'reset' == $_REQUEST['action'] ) {

            foreach ($options as $value) {
                delete_option( $value['id'] ); }

            header("Location: themes.php?page=theme-options.php&amp;reset=true");
            die;

        } else if ( 'reset_widgets' == $_REQUEST['action'] ) {
            $null = null;
            update_option('sidebars_widgets',$null);
            header("Location: themes.php?page=theme-options.php&amp;reset=true");
            die;
        }
    }

    add_theme_page($themename." Options", "Bibliteca Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');

}

function mytheme_admin() {

    global $themename, $shortname, $options;

    if ( $_REQUEST['saved'] ) echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;&lt;strong&gt;'.$themename.' '.__('settings saved.','thematic').'&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;';
    if ( $_REQUEST['reset'] ) echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;&lt;strong&gt;'.$themename.' '.__('settings reset.','thematic').'&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;';
    if ( $_REQUEST['reset_widgets'] ) echo '&lt;div id="message" class="updated fade"&gt;&lt;p&gt;&lt;strong&gt;'.$themename.' '.__('widgets reset.','thematic').'&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;';

?&gt;</code></pre><h2><span style="font-weight: normal;">Styling the elements</span></h2><p>The options page is actually just a table, with each element a new row, split into columns, so first, we need to start the table:</p><pre><code>&lt;div="wrap"&gt;

&lt;?php if ( function_exists('screen_icon') ) screen_icon(); ?&gt;

&lt;h2&gt;&lt;?php echo $themename; ?&gt; Options&lt;/h2&gt;

&lt;form method="post" action=""&gt;

&lt;table class="form-table"&gt;

&lt;?php foreach ($options as $value) {</code></pre><p>Next, we’re going to style each element, one by one. As I explained yesterday, we can do this once and the PHP will apply the styling multiple times.</p><h2>Styling the small text area</h2><p>This code must go underneath the code above, otherwise you’ll get lots of errors! As you can see, it’s just a table, echoing the values we entered yesterday:</p><pre><code>switch ( $value['type'] ) {
		case 'text':
		?&gt;
		&lt;tr valign="top"&gt;
			&lt;th scope="row"&gt;&lt;label for="&lt;?php echo $value['id']; ?&gt;"&gt;&lt;?php echo __($value['name'],'thematic'); ?&gt;&lt;/label&gt;&lt;/th&gt;
			&lt;td&gt;
				&lt;input name="&lt;?php echo $value['id']; ?&gt;" id="&lt;?php echo $value['id']; ?&gt;" type="&lt;?php echo $value['type']; ?&gt;" value="&lt;?php if ( get_option( $value['id'] ) != "") { echo get_option( $value['id'] ); } else { echo $value['std']; } ?&gt;" /&gt;
				&lt;?php echo __($value['desc'],'thematic'); ?&gt;

			&lt;/td&gt;
		&lt;/tr&gt;</code></pre><h2>Styling the large text area</h2><p>This too goes underneath the code above, and is much the same idea as before.</p><pre><code>&lt;?php
		break;

		case 'textarea':
		$ta_options = $value['options'];
		?&gt;
		&lt;tr valign="top"&gt;
			&lt;th scope="row"&gt;&lt;label for="&lt;?php echo $value['id']; ?&gt;"&gt;&lt;?php echo __($value['name'],'thematic'); ?&gt;&lt;/label&gt;&lt;/th&gt;
			&lt;td&gt;&lt;textarea name="&lt;?php echo $value['id']; ?&gt;" id="&lt;?php echo $value['id']; ?&gt;" cols="&lt;?php echo $ta_options['cols']; ?&gt;" rows="&lt;?php echo $ta_options['rows']; ?&gt;"&gt;&lt;?php
				if( get_option($value['id']) != "") {
						echo __(stripslashes(get_option($value['id'])),'thematic');
					}else{
						echo __($value['std'],'thematic');
				}?&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;?php echo __($value['desc'],'thematic'); ?&gt;&lt;/td&gt;
		&lt;/tr&gt;</code></pre><h2>Styling the title</h2><p>The title is breaking from the norm here by ending the table, displaying the title’s description and then restarting the table so the rest of the elements display fine:</p><pre><code>&lt;?php
		break;

		case 'nothing':
		$ta_options = $value['options'];
		?&gt;
		&lt;/table&gt;
			&lt;?php echo __($value['desc'],'thematic'); ?&gt;
		&lt;table class="form-table"&gt;</code></pre><h2>Styling the checkbox</h2><pre><code>&lt;?php
		break;

		case 'radio':
		?&gt;
		&lt;tr valign="top"&gt;
			&lt;th scope="row"&gt;&lt;?php echo __($value['name'],'thematic'); ?&gt;&lt;/th&gt;
			&lt;td&gt;
				&lt;?php foreach ($value['options'] as $key=&gt;$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 = "";
					}
				}?&gt;
				&lt;input type="radio" name="&lt;?php echo $value['id']; ?&gt;" id="&lt;?php echo $value['id'] . $key; ?&gt;" value="&lt;?php echo $key; ?&gt;" &lt;?php echo $checked; ?&gt; /&gt;&lt;label for="&lt;?php echo $value['id'] . $key; ?&gt;"&gt;&lt;?php echo $option; ?&gt;&lt;/label&gt;&lt;br /&gt;
				&lt;?php } ?&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;?php
		break;

		case 'checkbox':
		?&gt;
		&lt;tr valign="top"&gt;
			&lt;th scope="row"&gt;&lt;?php echo __($value['name'],'thematic'); ?&gt;&lt;/th&gt;
			&lt;td&gt;
				&lt;?php
					if(get_option($value['id'])){
						$checked = "checked=\"checked\"";
					}else{
						$checked = "";
					}
				?&gt;
				&lt;input type="checkbox" name="&lt;?php echo $value['id']; ?&gt;" id="&lt;?php echo $value['id']; ?&gt;" value="true" &lt;?php echo $checked; ?&gt; /&gt;
				&lt;label for="&lt;?php echo $value['id']; ?&gt;"&gt;&lt;?php echo __($value['desc'],'thematic'); ?&gt;&lt;/label&gt;
			&lt;/td&gt;
		&lt;/tr&gt;</code></pre><h2>Ending the options page</h2><pre><code>&lt;?php
		break;

		default:

		break;
	}
}
?&gt;

	&lt;/table&gt;

	&lt;p class="submit"&gt;
		&lt;input name="save" type="submit" value="&lt;?php _e('Save changes','thematic'); ?&gt;" /&gt;
		&lt;input type="hidden" name="action" value="save" /&gt;
	&lt;/p&gt;
&lt;/form&gt;
&lt;form method="post" action=""&gt;
	&lt;p class="submit"&gt;
		&lt;input name="reset" type="submit" value="&lt;?php _e('Reset','thematic'); ?&gt;" /&gt;
		&lt;input type="hidden" name="action" value="reset" /&gt;
	&lt;/p&gt;
&lt;/form&gt;

&lt;p&gt;Biblioteca theme.&lt;/p&gt;
&lt;/div&gt;
&lt;?php
}

add_action('admin_menu' , 'mytheme_add_admin'); 

?&gt;</code></pre><p>With all the code above in our functions.php file, we can end the table, add save and reset buttons and close up all the loose ends. With that, we’re done creating the options page itself. All that is left to do is merge the functions-options.php and functions.php file. Make sure you first create a backup of the original functions.php file before merging the two files. With the two files merged, refresh the WordPress backend and you should see your new options page! If you’re getting any errors, make sure you’ve put the code outside closing</p><pre><code>?&gt;</code></pre><p>and wrapped your own code in</p><pre><code>&lt;?php and ?&gt;</code></pre><p>. If that doesn’t fix it, restore the original file and leave a comment with your problem, with <em>as much detail as possible</em>.</p><h2>Wrapping up</h2><p>If you haven’t already noticed, the download that includes all of the code used in today’s tutorial is available at the top of the page, to save you copying and pasting it. Tomorrow we’ve got the exciting job of implementing all of the options we’ve created, and until then, why not [f], leave a comment and <a href="http://feeds2.feedburner.com/nometech">subscribe by RSS</a>!</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-3/">Create An Advanced Theme Options Page in WordPress: Day 3</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-3/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> <item><title>Create An Advanced Options Page in WordPress: Day 2</title><link>http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/</link> <comments>http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/#comments</comments> <pubDate>Tue, 06 Oct 2009 15:00:18 +0000</pubDate> <dc:creator>Alex Denning</dc:creator> <category><![CDATA[Theme Options Page]]></category><guid isPermaLink="false">http://wpshout.com/?p=1300</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/">Create An Advanced Options Page in WordPress: Day 2</a></p></p><p>Day two of creating an advanced theme options page in WordPress. In this post we get started creating the theme options page.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/">Create An Advanced Options Page in WordPress: Day 2</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/">Create An Advanced Options Page in WordPress: Day 2</a></p></p><p>Continuing <a href="http://wpshout.com">WPShout</a>&#8216;s series on <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Creating an Advanced Theme Options Page in WordPress</a>, today we&#8217;re going to be creating the different options.</p><p><a href="http://wpshout.com/downloads/theme-options-day-2.txt"><img class="alignnone size-full wp-image-1313" title="download-2" src="http://wpshout.com/wp-content/uploads/2009/10/download-2.jpg" alt="download-2" width="590" height="250" /></a></p><li><a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Day 1: Introduction</a></li><li><strong>Day 2: Creating the different options</strong></li><li>Day 3: Styling the options page</li><li>Day 4: Implementing the options into a theme</li><p>Introduced yesterday, this is the second installment of this month’s themed week – create an advanced options page in WordPress. Today we’re going to be creating the different types of options that we can use in our theme options page. The code used in this tutorial comes from my WordPress theme, <em><a href="http://wpshout.com/free-wordpress-magazineframeworkbloggytech-blog-theme-biblioteca/">Biblioteca</a>.</em></p><h2>Types of options</h2><p><span style="font-weight: normal; font-size: 13px;">There are four different ‘types’ of options we’re going to create today: title, large text box, small text box and checkbox. With these four different types of options available to us, we’ll be able to cover all the bases – give users the option to show and hide elements, enter ad codes, Feedburner addresses – anything really. However, as we’re creating an <em>advanced</em> options page here’s a screen of the full options page we’ll be creating over the week:</span></p><p><span style="font-weight: normal; font-size: 13px;"><a href="http://wpshout.com/wp-content/uploads/2009/09/themeoptionsscreen.jpg"><img class="alignnone size-full wp-image-1296" title="themeoptionsscreen" src="http://wpshout.com/wp-content/uploads/2009/09/themeoptionsscreen.jpg" alt="themeoptionsscreen" width="590" /></a></span></p><p><em>Fig 2.1: The Options Page We’re Creating</em></p><p>As the image above shows, there are four main elements to our options page. First is the Feedburner URL, next is letting the user choose a layout, after that showing and hiding various elements and finally text areas for ad codes, footer text and Analytics code.</p><h2>Getting started</h2><p>So let’s get started. The template file we’re using to create the options page is called the functions.php file, but we’re not going to start putting data straight into that just yet, so instead open up your code editor of choice and create a new file, functions-options.php. Save this new file with your theme files.</p><p>Open it up in your editor of choice. First, we need to specify a ‘themename’ and ‘shortname’. The ‘themename’ should be your theme’s name and ‘shortname’ a shortened version of it. For example, Biblioteca is shortened to ‘blt’:</p><pre><code>&lt;?php

// Create your own options page --&gt; <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">http://wpshout.com/create-an-advanced-options-page-in-wordpress/</a>

$themename = "Bibliteca";

$shortname = "blt";</code></pre><h2>Creating a small text box</h2><p><a href="http://wpshout.com/wp-content/uploads/2009/10/smallbox.jpg"><img class="alignnone size-full wp-image-1307" title="smallbox" src="http://wpshout.com/wp-content/uploads/2009/10/smallbox.jpg" alt="smallbox" width="590" /></a></p><p>Fig 2.2: an example small text box</p><p>Simple enough so far. Next we move onto a PHP array that lets us specify various elements we want to be displayed, and then style these elements, applying the same styling multiple times. Simpler, we’re going to fill out various boxes with the information about our theme options. Tomorrow we’re going to by styling them. The first of our options is the Feedburner URL. We’ve got five different options we can specify: title of the element, description, an ID, what is displayed by standard and what type of input to offer. We want to name our element ‘Feedburner URL’, with a description ‘Copy and paste your Feedburner URL here’. We want an ID of ‘_feedburner’, standard text of ‘http://feeds2.feedburner.com/’ and an input type of text. We can achieve that with the code below:</p><pre><code>array(

"name" =&gt; __('Feedburner URL'),

"desc" =&gt; __("Copy and paste your Feedburner URL"),

"id" =&gt; $shortname."_feedburner",

"std" =&gt; "http://feeds2.feedburner.com/",

"type" =&gt; "text"),</code></pre><p>To create other options we’re effectively just copying and pasting the code, changing the different elements we want. If you want a small text box, use the code above as a base. We’ll now do a single example of each of the types of element we’re going to be creating.</p><h2>Creating a title</h2><p><a href="http://wpshout.com/wp-content/uploads/2009/10/title.jpg"><img class="alignnone size-full wp-image-1316" title="title" src="http://wpshout.com/wp-content/uploads/2009/10/title.jpg" alt="title" width="407" height="40" /></a></p><p>Fig 2.3: An example title</p><p>The next element down on our options page is a title. The title hasn’t got too many different fields we need to fill in, just a description and a type, so to have a title ‘Choose a layout below’ we need the following code:</p><pre><code>array(

"desc" =&gt; __("&lt;h3&gt;Choose a layout below&lt;/h3&gt;"),

"type" =&gt; "title"),</code></pre><p>You’ll notice the ‘Choose a layout’ is in an &lt;h3&gt; tag, so that it stands out.</p><h2>Creating a checkbox</h2><p><a href="http://wpshout.com/wp-content/uploads/2009/10/checkbox.jpg"><img class="alignnone size-full wp-image-1306" title="checkbox" src="http://wpshout.com/wp-content/uploads/2009/10/checkbox.jpg" alt="checkbox" width="425" height="44" /></a></p><p>Fig 2.4: An example checkbox</p><p>The third element we need is a checkbox that lets the user enable or disable elements. To create a checkbox with the option to hide ‘Sidebar Area 1’, a the description ‘Hide Sidebar Area 1?’, ID ‘_sidebar_area_1’ and a standard of false (or in other words the box unchecked; the option is ‘true’) we’ll need the following code:</p><pre><code>array(

"name" =&gt; __('Sidebar Area 1'),

"desc" =&gt; __("Hide Sidebar Area 1?"),

"id" =&gt; $shortname."_sidebar_area_1",

"std" =&gt; "false",

"type" =&gt; "checkbox"),</code></pre><p>Again, this can be changed to create other elements. For example, if we wanted the option ‘Hide Homepage Area 1’ we’d need the following:</p><pre><code>array(

"name" =&gt; __('Homepage Area 1'),

"desc" =&gt; __("Hide Homepage Area 1?"),

"id" =&gt; $shortname."_home_area_1",

"std" =&gt; "false",

"type" =&gt; "checkbox"),</code></pre><h2>Creating a large textbox</h2><p><a href="http://wpshout.com/wp-content/uploads/2009/10/largebox.jpg"><img class="alignnone size-full wp-image-1311" title="largebox" src="http://wpshout.com/wp-content/uploads/2009/10/largebox.jpg" alt="largebox" width="492" height="148" /></a></p><p>Fig 2.5: An example large text box</p><p>The final element we need is a large text box. One of the large text boxes was where the user could paste an ad code for an advert size 300&#215;250. We can create one with the following:</p><pre><code>array(     "name" =&gt; __('Ad code at 300x250 size'),

"desc" =&gt; __("Copy and paste into the box below your advert code at 300x250 size"),

"id" =&gt; $shortname."_300_250_ad",

"std" =&gt; __(""),

"type" =&gt; "textarea",

"options" =&gt; array(

"rows" =&gt; "5",

"cols" =&gt; "94") ),</code></pre><p>The first three lines should look familiar by now, and as we don’t want anything to be displayed as standard, the space between the quotation marks is blank. The type for a large text area is ‘textarea’. Now you’ll notice we’ve got a couple more options – rows and columns. These are setting the height and width of the text box.</p><h2>Changing things <em>slightly</em></h2><p>We’ve now created an example of each of the main elements, and to create others you just change the name, description etc. I’m not going to create a single example for each. Instead, you can download a txt file at the top of the post with all of the options already in it. Note that it won’t actually do anything at the minute and will probably land you with a big error; you need tomorrow’s styling for the page to display properly. Make sure you <a href="http://feeds2.feedburner.com/nometech">subscribe by RSS</a> and <a href="http://twitter.com/alexdenning">follow me on Twitter</a> to catch it!</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/">Create An Advanced Options Page in WordPress: Day 2</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Create An Advanced Theme Options Panel in WordPress</title><link>http://wpshout.com/create-an-advanced-options-page-in-wordpress/</link> <comments>http://wpshout.com/create-an-advanced-options-page-in-wordpress/#comments</comments> <pubDate>Mon, 05 Oct 2009 15:00:34 +0000</pubDate> <dc:creator>Alex Denning</dc:creator> <category><![CDATA[Theme Options Page]]></category><guid isPermaLink="false">http://wpshout.com/?p=1295</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Create An Advanced Theme Options Panel in WordPress</a></p></p><p>Creating an advanced theme options page in WordPress has never been easier with this series of tutorials from WPShout.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Create An Advanced Theme Options Panel in WordPress</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Create An Advanced Theme Options Panel in WordPress</a></p></p><p>This is the start of <a href="http://wpshout.com">WPShout</a>&#8216;s second ‘themed week’, which run every first week of the month. Last month we got <a href="http://wpshout.com/category/themes/a-beginners-guide-to-wordpress-theme-development-themes/">started with WordPress theme development</a> and this month we’re going to be creating an advanced theme options page.</p><p>Creating a WordPress theme options page is something that <a href="http://wpshout.com/create-an-awesome-wordpress-theme-options-page-part-1/">we’ve touched on before</a> on <a href="http://wpshout.com">WPShout</a>, and this week we’ll be expanding on what we covered before to create not just a theme options page, but an <em>advanced</em> theme options page; we’ll be creating something that lets users change layouts, hide and display different elements dotted around the theme, enter ad codes, footer text, tracking codes, Feedburner URLs, anything really:</p><p><a style="text-decoration: none;" href="http://wpshout.com/wp-content/uploads/2009/09/themeoptionsscreen.jpg"><img class="alignnone size-full wp-image-1296" title="themeoptionsscreen" src="http://wpshout.com/wp-content/uploads/2009/09/themeoptionsscreen.jpg" alt="themeoptionsscreen" width="590" /></a></p><p>This is a screen of the options page we’ll be creating over the next couple of days – as you can see, pretty impressive! The plan for the week is as follows:</p><ul><li><strong>Day 1: Introduction</strong></li><li><a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress-part-2/">Day 2: Creating the different options</a></li><li><a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-3/">Day 3: Styling the options page</a></li><li><a href="http://wpshout.com/create-an-advanced-theme-options-page-in-wordpress-day-4/">Day 4: Implementing the options into a theme</a></li></ul><p>And that’s pretty much it. Unlike <a href="http://wpshout.com/category/themes/a-beginners-guide-to-wordpress-theme-development-themes/">last time</a> there won&#8217;t be a free eBook to download at the end of the week, but this is a shorter series at only four days. Throughout the week you’ll be most welcome to ask any questions etc etc through the comments, and I’d ask if you’re going to save the series to any social media site then please save this post. The code for the tutorial series comes from my WordPress theme framework, <a href="http://wpshout.com/free-wordpress-magazineframeworkbloggytech-blog-theme-biblioteca/">Biblioteca</a> (that in turn is based on <a href="http://themeshaper.com">Thematic&#8217;s </a>options page).</p><p>That’s all the admin stuff out the way, so <a href="http://feeds2.feedburner.com/nometech">subscribe by RSS</a>, save this post to Delicious and grab a cup of tea. It’s going to be an interesting week.</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-advanced-options-page-in-wordpress/">Create An Advanced Theme Options Panel in WordPress</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/create-an-advanced-options-page-in-wordpress/feed/</wfw:commentRss> <slash:comments>25</slash:comments> </item> <item><title>Add A Meta Box In WordPress</title><link>http://wpshout.com/create-an-in-post-theme-options-meta-box-in-wordpress/</link> <comments>http://wpshout.com/create-an-in-post-theme-options-meta-box-in-wordpress/#comments</comments> <pubDate>Mon, 24 Aug 2009 15:00:31 +0000</pubDate> <dc:creator>Alex Denning</dc:creator> <category><![CDATA[Theme Options Page]]></category> <category><![CDATA[Custom Fields]]></category> <category><![CDATA[In Post Options]]></category><guid isPermaLink="false">http://wpshout.com/?p=1020</guid> <description><![CDATA[<p><p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-in-post-theme-options-meta-box-in-wordpress/">Add A Meta Box In WordPress</a></p></p><p>Create your own in-post options in WordPress; this tutorial will show you how to add your own 'boxes', 'meta boxes', 'in-post options'; whatever you want to call them, to your own WordPress theme. All through the power of custom fields.</p></p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-in-post-theme-options-meta-box-in-wordpress/">Add A Meta Box In WordPress</a></p></p>]]></description> <content:encoded><![CDATA[<p><p>Lots of posts on WPShout are art directed, so you may wish to view this in your browser --> <a href="http://wpshout.com/create-an-in-post-theme-options-meta-box-in-wordpress/">Add A Meta Box In WordPress</a></p></p><p>Creating the options pages is something we&#8217;ve touched upon previously here on <a href="http://wpshout.com">WPShout</a>, and whilst developing my soon-to-be-released WordPress <a href="http://wpshout.com/category/themes/">theme</a>, <em>Biblioteca</em>, I wanted to add some options to the post writing page, and in this post I&#8217;m going to be sharing how I did it.</p><p><a href="http://wpshout.com/downloads/post-options.txt"><img class="alignnone size-full wp-image-1073" title="in-post-download" src="http://wpshout.com/wp-content/uploads/2009/08/in-post-download.jpg" alt="in-post-download" width="590" height="250" /></a></p><h2>How the in-post options work</h2><p>Basically, we&#8217;re going to be adding some boxes to the post and page writing pages that give our users a number of options, including customising the &lt;title&gt; tag, the meta description and the URL of a featured image:</p><p><img class="alignnone" title="Post options" src="http://nometech.com/wpshout.com/wp-content/uploads/images/9tcazi.png" alt="" width="562" height="268" /></p><p>These options get displayed immediately below the post/page writing area, and the user can enter text. This text, when the post is saved gets saved as custom fields. For example, on this post I&#8217;ll enter some text &#8220;Hello. This is a test.&#8221;  in the &#8220;Image&#8221; field. The results are below:</p><p><img class="alignnone" title="Result!" src="http://nometech.com/wpshout.com/wp-content/uploads/images/18iu98.png" alt="" width="557" height="415" /></p><p>So that proves it works! Let&#8217;s get straight into implementing it. First off, all credits go to Justin Tadlock &#8211; code comes more or less straight out of <a href="http://themehybrid.com/themes/hybrid">Hybrid</a>.</p><h2>Making the in post options</h2><p>The first thing you need to do in order to make your own in post options is to open up your functions.php file. This is the file that gives you a lot of power, but can also totally wreck your theme &#8211; power comes with responsibility! Always have a backup readily to hand.</p><p>The first code to add is the following, which does the job of adding the box to the admin menu:</p><pre><code>&lt;?php
/**
Made with the help of a tutorial at WPShout.com =&gt; http://wpshout.com.

Courtesy of the Hybrid theme - themehybrid.com

/* Add a new meta box to the admin menu. */
	add_action( 'admin_menu', 'hybrid_create_meta_box' );

/* Saves the meta box data. */
	add_action( 'save_post', 'hybrid_save_meta_data' );

/**
 * Function for adding meta boxes to the admin.
 * Separate the post and page meta boxes.

function hybrid_create_meta_box() {
	global $theme_name;

	add_meta_box( 'post-meta-boxes', __('Post options'), 'post_meta_boxes', 'post', 'normal', 'high' );
	add_meta_box( 'page-meta-boxes', __('Post options'), 'page_meta_boxes', 'page', 'normal', 'high' );
}</code></pre><p>With that added, the next step is to start an array which will be the text used by the options page. The &#8216;name&#8217; is the name of the custom field that will be generated by the options. Next is the text displayed on the right and finally the &#8216;type&#8217; is what type of box the theme is to display; either the large textarea or the smaller single line text:</p><pre><code>function hybrid_post_meta_boxes() {

	/* Array of the meta box options. */
	$meta_boxes = array(
		'title' =&gt; array( 'name' =&gt; 'Title', 'title' =&gt; __('Title', 'hybrid'), 'type' =&gt; 'text' ),
		'description' =&gt; array( 'name' =&gt; 'Description', 'title' =&gt; __('Description', 'hybrid'), 'type' =&gt; 'textarea' ),
		'image' =&gt; array( 'name' =&gt; 'Image', 'title' =&gt; __('Image:', 'hybrid'), 'type' =&gt; 'text' ),
		'featured' =&gt; array( 'name' =&gt; 'Featured', 'title' =&gt; __('Featured img:', 'hybrid'), 'type' =&gt; 'text' ),

	);

	return apply_filters( 'hybrid_post_meta_boxes', $meta_boxes );
}</code></pre><p>You&#8217;ll notice the last bit of code is for pages only, where no featured image option is added.</p><p>Next, the code that displays the boxes and formats them:</p><pre><code>function post_meta_boxes() {
	global $post;
	$meta_boxes = hybrid_post_meta_boxes(); ?&gt;

	&lt;table class="form-table"&gt;
	&lt;?php foreach ( $meta_boxes as $meta ) :

		$value = get_post_meta( $post-&gt;ID, $meta['name'], true );

		if ( $meta['type'] == 'text' )
			get_meta_text_input( $meta, $value );
		elseif ( $meta['type'] == 'textarea' )
			get_meta_textarea( $meta, $value );
		elseif ( $meta['type'] == 'select' )
			get_meta_select( $meta, $value );

	endforeach; ?&gt;
	&lt;/table&gt;
&lt;?php
}

/**
 * Displays meta boxes on the Write Page panel.  Loops
 * through each meta box in the $meta_boxes variable.
 * Gets array from hybrid_page_meta_boxes()
 *
 * @since 0.3
 */
function page_meta_boxes() {
	global $post;
	$meta_boxes = hybrid_page_meta_boxes(); ?&gt;

	&lt;table class="form-table"&gt;
	&lt;?php foreach ( $meta_boxes as $meta ) :

		$value = stripslashes( get_post_meta( $post-&gt;ID, $meta['name'], true ) );

		if ( $meta['type'] == 'text' )
			get_meta_text_input( $meta, $value );
		elseif ( $meta['type'] == 'textarea' )
			get_meta_textarea( $meta, $value );
		elseif ( $meta['type'] == 'select' )
			get_meta_select( $meta, $value );

	endforeach; ?&gt;
	&lt;/table&gt;
&lt;?php
}

/**
 * Outputs a text input box with arguments from the
 * parameters.  Used for both the post/page meta boxes.
 *
 * @since 0.3
 * @param array $args
 * @param array string|bool $value
 */
function get_meta_text_input( $args = array(), $value = false ) {

	extract( $args ); ?&gt;

	&lt;tr&gt;
		&lt;th style="width:10%;"&gt;
			&lt;label for="&lt;?php echo $name; ?&gt;"&gt;&lt;?php echo $title; ?&gt;&lt;/label&gt;
		&lt;/th&gt;
		&lt;td&gt;
			&lt;input type="text" name="&lt;?php echo $name; ?&gt;" id="&lt;?php echo $name; ?&gt;" value="&lt;?php echo wp_specialchars( $value, 1 ); ?&gt;" size="30" tabindex="30" style="width: 97%;" /&gt;
			&lt;input type="hidden" name="&lt;?php echo $name; ?&gt;_noncename" id="&lt;?php echo $name; ?&gt;_noncename" value="&lt;?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?&gt;" /&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;?php
}

/**
 * Outputs a select box with arguments from the
 * parameters.  Used for both the post/page meta boxes.
 *
 * @since 0.3
 * @param array $args
 * @param array string|bool $value
 */
function get_meta_select( $args = array(), $value = false ) {

	extract( $args ); ?&gt;

	&lt;tr&gt;
		&lt;th style="width:10%;"&gt;
			&lt;label for="&lt;?php echo $name; ?&gt;"&gt;&lt;?php echo $title; ?&gt;&lt;/label&gt;
		&lt;/th&gt;
		&lt;td&gt;
			&lt;select name="&lt;?php echo $name; ?&gt;" id="&lt;?php echo $name; ?&gt;"&gt;
			&lt;?php foreach ( $options as $option ) : ?&gt;
				&lt;option &lt;?php if ( htmlentities( $value, ENT_QUOTES ) == $option ) echo ' selected="selected"'; ?&gt;&gt;
					&lt;?php echo $option; ?&gt;
				&lt;/option&gt;
			&lt;?php endforeach; ?&gt;
			&lt;/select&gt;
			&lt;input type="hidden" name="&lt;?php echo $name; ?&gt;_noncename" id="&lt;?php echo $name; ?&gt;_noncename" value="&lt;?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?&gt;" /&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;?php
}

/**
 * Outputs a textarea with arguments from the
 * parameters.  Used for both the post/page meta boxes.
 *
 * @since 0.3
 * @param array $args
 * @param array string|bool $value
 */
function get_meta_textarea( $args = array(), $value = false ) {

	extract( $args ); ?&gt;

	&lt;tr&gt;
		&lt;th style="width:10%;"&gt;
			&lt;label for="&lt;?php echo $name; ?&gt;"&gt;&lt;?php echo $title; ?&gt;&lt;/label&gt;
		&lt;/th&gt;
		&lt;td&gt;
			&lt;textarea name="&lt;?php echo $name; ?&gt;" id="&lt;?php echo $name; ?&gt;" cols="60" rows="4" tabindex="30" style="width: 97%;"&gt;&lt;?php echo wp_specialchars( $value, 1 ); ?&gt;&lt;/textarea&gt;
			&lt;input type="hidden" name="&lt;?php echo $name; ?&gt;_noncename" id="&lt;?php echo $name; ?&gt;_noncename" value="&lt;?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?&gt;" /&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
	&lt;?php
}
</code></pre><p>And finally, saving the options entered as custom fields:</p><pre><code>/**
 * Loops through each meta box's set of variables.
 * Saves them to the database as custom fields.
 *
 * @since 0.3
 * @param int $post_id
 */
function hybrid_save_meta_data( $post_id ) {
	global $post;

	if ( 'page' == $_POST['post_type'] )
		$meta_boxes = array_merge( hybrid_page_meta_boxes() );
	else
		$meta_boxes = array_merge( hybrid_post_meta_boxes() );

	foreach ( $meta_boxes as $meta_box ) :

		if ( !wp_verify_nonce( $_POST[$meta_box['name'] . '_noncename'], plugin_basename( __FILE__ ) ) )
			return $post_id;

		if ( 'page' == $_POST['post_type'] &amp;&amp; !current_user_can( 'edit_page', $post_id ) )
			return $post_id;

		elseif ( 'post' == $_POST['post_type'] &amp;&amp; !current_user_can( 'edit_post', $post_id ) )
			return $post_id;

		$data = stripslashes( $_POST[$meta_box['name']] );

		if ( get_post_meta( $post_id, $meta_box['name'] ) == '' )
			add_post_meta( $post_id, $meta_box['name'], $data, true );

		elseif ( $data != get_post_meta( $post_id, $meta_box['name'], true ) )
			update_post_meta( $post_id, $meta_box['name'], $data );

		elseif ( $data == '' )
			delete_post_meta( $post_id, $meta_box['name'], get_post_meta( $post_id, $meta_box['name'], true ) );

	endforeach;
}
?&gt;</code></pre><p>And we&#8217;re done creating the options! Next, we&#8217;re going to be implementing these options.</p><h2>Giving the user the option to change the title tag <em>without </em>a plugin</h2><p>The first field/option we offered was &#8220;Title&#8221;. Obviously we&#8217;re going to use this as the &lt;title&gt; tag for our post. How? As you may recall, the text input into the boxes gets spitted out as a custom field, so we can display the &#8220;Title&#8221; as the title tag with the following (open up the header.php):</p><pre><code>&lt;title&gt;&lt;?php echo get_post_meta($post-&gt;ID, "Title", true); ?&gt;&lt;/title&gt;</code></pre><p>But that would be a seriously bad idea. What if it&#8217;s the homepage?! What if there is no custom field?! The folllowing is <em>much</em> better; it should be used <em>in conjunction</em> with your current SEO&#8217;d setup, will only display on posts and pages <em>and</em> has an option for <em>if no custom field exists:</em></p><pre><code>&lt;?php if ( is_single() || is_page() ) { ?&gt;&lt;?php $title = get_post_meta($post-&gt;ID, 'Title', true);  if ($title) { ?&gt;
&lt;?php echo get_post_meta($post-&gt;ID, &quot;Title&quot;, true); ?&gt;&nbsp;|&nbsp;&lt;?php bloginfo('name'); ?&gt;
&lt;?php } else { ?&gt;
&lt;?php wp_title(''); ?&gt;&nbsp;|&nbsp;&lt;?php bloginfo('name'); ?&gt;
&lt;?php } ?&gt;
&lt;?php } ?&gt;</code></pre><h2>Giving the user the option to change the meta description <em>without</em> a plugin</h2><p>The second field was &#8216;Description&#8217;. This is your meta description, an important part of your SEO strategy. Similar code to the above will display the content of the box, but with a fall back for <em>if no custom field exists</em>:</p><pre><code>lt;?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;
&lt;meta name=&quot;description&quot; content=&quot;&lt;?php $description = get_post_meta($post-&gt;ID, 'Description', true);  if ($description) { ?&gt;&lt;?php echo get_post_meta($post-&gt;ID, &quot;Description&quot;, true); ?&gt;
&lt;?php } else { ?&gt;&lt;?php the_excerpt_rss(); ?&gt;&lt;?php } ?&gt;&quot; /&gt;
&lt;?php endwhile; endif; elseif(is_home()) : ?&gt;
&lt;meta name=&quot;description&quot; content=&quot;&lt;?php bloginfo('description'); ?&gt;&quot; /&gt;
&lt;?php endif; ?&gt;</code></pre><h2>Displaying images</h2><p>The final field was the URL for a &#8216;featured&#8217; image. We can integrate this into our WordPress theme with the following:</p><pre><code>&lt;?php $postimageurl = get_post_meta($post-&gt;ID, 'Image', true); if ($postimageurl) { ?&gt;
&lt;img src="&lt;?php bloginfo('template_url'); ?&gt;/scripts/timthumb.php?src=&lt;?php echo get_post_meta($post-&gt;ID, "Image", true); ?&gt;&amp;h=250&amp;w=250&amp;zc=1" alt=""&gt; </code>
<code>&lt;?php }else { ?&gt; </code>
<code>&lt;img src="&lt;?php bloginfo('template_url'); ?&gt;/images/noimage.jpg" alt="No image available" /&gt;
&lt;?php } ?&gt;</code></pre><h2>Concluding</h2><p>With that, we&#8217;re finished creating our in post options! The download for the code is available at the top of the post. This is a brilliant, simple <em>and</em> effective way to<a href="http://wpshout.com/10-tips-to-improve-your-wordpress-theme/"> improve your WordPress theme</a>.</p><p>If you have enjoyed this post, please take a second to save it to your favourite social bookmarking site with the links below and even <a href="http://feeds2.feedburner.com/nometech">subscribe by RSS</a> or <a href="http://twitter.com/alexdenning">follow me on Twitter</a>! Any questions, suggestions or queries, please do leave a comment.</p><p><p>This is a post from <a href="http://wpshout.com">WPShout</a>. If you enjoyed the post, please head over to the site and share or leave a comment! --> <a href="http://wpshout.com/create-an-in-post-theme-options-meta-box-in-wordpress/">Add A Meta Box In WordPress</a></p></p>]]></content:encoded> <wfw:commentRss>http://wpshout.com/create-an-in-post-theme-options-meta-box-in-wordpress/feed/</wfw:commentRss> <slash:comments>45</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 31/46 queries in 0.036 seconds using disk
Content Delivery Network via wpshout.wpcdn.com

Served from: wpshout.com @ 2012-02-04 04:19:56 -->
