<?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>Nettuts+ &#187; Wordpress</title>
	<atom:link href="http://net.tutsplus.com/category/tutorials/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://net.tutsplus.com</link>
	<description>Web Development &#38; Design Tutorials</description>
	<lastBuildDate>Fri, 20 Nov 2009 19:56:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>10 WordPress 2.8 Features To Look Out For</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/10-wordpress-28-features-to-look-out-for/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/10-wordpress-28-features-to-look-out-for/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 22:34:43 +0000</pubDate>
		<dc:creator>Andrew Turner</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wordpress 2.8]]></category>
		<category><![CDATA[wordpress features]]></category>

		<guid isPermaLink="false">http://net.tutsplus.com/?p=5513</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/356_wp28/200x200.jpg" alt="10 WordPress 2.8 Features To Look Out For" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a great achievement for WordPress 2.8 to be released so soon after 2.7. Named &#8216;Baker&#8217;, 2.8 adds plenty of new features,  including syntax highlighting for theme/plugin editing, a theme installer, and a great revamped widgets interface and API.
</p>
<p><span id="more-5513"></span></p>
<h3>1. Dashboard Columns</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/columns.jpg" border="0" /></div>
<p>You can now sort your dashboard into columns, which is a great feature for those who are small or large on screen space. You can set up to 4 columns and drag and drop different widgets. I found it to be a good feature as I like re-arrange my dashboard and management pages to suit my workspace. This will surely appeal to many users.</p>
<h3>2. Password Reminder</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/password.jpg" border="0" /></div>
<p>Just installed WordPress? This is the feature for those that forget to change their admin account password after a fresh install. It displays a big notice across the top of the admin area until you change it.</p>
<h3>3. Theme Installer</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/theme.jpg" border="0" /></div>
<p>In WordPress 2.7, you could install plugins directly through your installation. Now, the same feature has been ported to themes, allowing you to install any theme directory into your WordPress site. Installing is as easy as installing plugins &#8212; through the click of a button.</p>
<h3>4. Theme/Plugin Editor &#8211; Syntax Highlighter &amp; Function Reference</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/syntax.jpg" border="0" /></div>
<p>This is a feature that I&#8217;ve been looking forward to, along with many other developers. WordPress now has syntax highlighting thanks to <a href="http://codepress.sourceforge.net">CodePress</a>. This means you can find functions and browse through code much easier,  as you would with your code editor. </p>
<p>You&#8217;ll also find a Documentation lookup, as so you can quickly reference WordPress functions through the Codex. These new features will speed up development of WordPress themes even further by having the tools right in front of you for quick &amp; easy access.</p>
<h3>5. Widgets Interface</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/widgets.jpg" border="0" /></div>
<p>WordPress&#8217; widgets management interface was a bit plain and simple.  That&#8217;s no longer true with the brand new widgets interface allowing you to sort and manage your theme&#8217;s widgets more efficiently. It still uses the drag and drop method of adding/removing widgets, but takes the active/inactive widgets one step further separating them from each other. </p>
<h3>6. Widgets API</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/widgetsapi.jpg" border="0" /></div>
<p>Creating widgets is now easier than ever before with the new widgets API. All you have to do is extend the basic class and functions, and you can easily create a widget with options and more. Here&#8217;s an example widget using the new API; it&#8217;s been coded to allow the user to set the title, but display predefined content. </p>
<pre name="code" class="php">
&lt;?php
/*
Plugin Name: Example Widget
Plugin URI:
Description: An example widget using the WordPress 2.8 Widget API.
Version: 1.0.0
Author: Andrew Turner
Author URI: http://andrew-turner.com
*/
class exWidget extends WP_Widget {
    /* Constructs Widget */
    function exWidget() {
        parent::WP_Widget(false, $name = 'exWidget');
    }

    /* Widget Base */
    function widget($args, $instance) {
        extract( $args );
        ?>
              &lt;?php echo $before_widget; ?>
                  &lt;?php echo $before_title
                      . $instance['title']
                      . $after_title; ?>
                  &lt;?php echo 'Hello There!' ?>
              &lt;?php echo $after_widget; ?>
        &lt;?php
    }

    function update($new_instance, $old_instance) {
        return $new_instance;
    }

    /* Options Form */
    function form($instance) {
        $title = esc_attr($instance['title']);
        ?>
            &lt;p>&lt;label for="&lt;?php echo $this->get_field_id('title'); ?>">&lt;?php _e('Title:'); ?> &lt;input class="widefat" id="&lt;?php echo $this->get_field_id('title'); ?>" name="&lt;?php echo $this->get_field_name('title'); ?>" type="text" value="&lt;?php echo $title; ?>" />&lt;/label>&lt;/p>
        &lt;?php
    }
}
/* Register Widget */
add_action('widgets_init', create_function('', 'return register_widget("exWidget");'));
?>
</pre>
<h3>7. Timezones and DST</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/timezones.jpg" border="0" /></div>
<p>WordPress now supports timezones, and the ability to automatically update when it comes around to daylight savings. This is a new feature, and was not found in previous versions. </p>
<h3>8. Custom Taxonomies</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/taxonomy.jpg" border="0" /></div>
<p>A Taxonomy is essentially a way that things are grouped or divided. WordPress 2.8 improves upon its Taxonomies by allowing you to develop your own. By default, WordPress includes three of its own.</p>
<ul>
<li>category</li>
<li>post_tag</li>
<li>link_category</li>
</ul>
<p>Uses for custom taxonomies might include making post series or more. Here&#8217;s an example of creating a custom taxonomy, the code is placed in your theme&#8217;s functions.php file.</p>
<pre name="code" class="php">
&lt;?php
add_action( 'init', 'custom_taxonomies', 0 );
function custom_taxonomies() {
	register_taxonomy( 'version', 'post', array( 'hierarchical' => false, 'label' => 'Version', 'query_var' => true, 'rewrite' => true ) );
	register_taxonomy( 'released', 'post', array( 'hierarchical' => true, 'label' => 'Released', 'query_var' => true, 'rewrite' => true ) );
	register_taxonomy( 'downloads', 'post', array( 'hierarchical' => false, 'label' => 'Downloads', 'query_var' => true, 'rewrite' => true ) );
}
?>
</pre>
<p>To understand how to create your own taxonomy, you need to understand what&#8217;s behind the code. Here&#8217;s a breakdown of the following example:</p>
<pre name="code" class="php">
	register_taxonomy( 'version', 'post', array( 'hierarchical' => false, 'label' => 'Version', 'query_var' => true, 'rewrite' => true ) );
</pre>
<ul>
<li><strong>version</strong> :  Tells WordPress the name of your taxonomy.</li>
<li><strong>post</strong> : Tells WordPress what type of content this applies to; you could apply your taxonomy to pages or even links if you wanted too. Though WordPress handles custom taxonomies with posts best.</li>
<li><strong>hierarchical</strong> :  Asks whether  the taxonomy&#8217;s terms can be shown in a hierarchy (A hierarchy is setup like a tree of items, eg: categories.). You can set this to true for the terms to be organized  like categories, or false for them to behave like tags.</li>
<li><strong>label</strong> : The name of your taxonomy that will be seen in the WordPress admin for posts, pages or links.</li>
<li><strong>query_var</strong> : A parameter  that lets WordPress know if you want to retrieve your posts through a query &#8212; for example showing all posts which relate to the product released in 2008. If you&#8217;ve set your taxonomy so you can query it, remember the variable for the query will be the name of your taxonomy.</li>
<li><strong>rewrite</strong> : Whether you&#8217;d like to allow WordPress to use your permalink structure when viewing the archives or taxonomy page. Eg, instead of yourproduct.net/?released=2008 it could become yourproduct.com/released/2008.</li>
</ul>
<h3>9. Faster Administration Pages</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/speed.jpg" border="0" /></div>
<p>The WordPress team have sped up the administration pages (E.g: Posts, Comments, Settings, etc) through script compression and concatenation. Now, you can perform tasks quicker and easier. Take note of the fact that this feature doesn&#8217;t apply to the front end of your WordPress website.</p>
<h3>10. Plugin Management Updated</h3>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/356_wp28/plugins.jpg" border="0" /></div>
<p>The plugin management interface that allows you to activate and deactivate plugins has been updated with a new layout &#8211; it still heralds the same features as in WordPress 2.7, but with a different layout. You&#8217;ll find that they&#8217;ve been put together in a list on the single page, but there&#8217;s an option to view different statuses such as:</p>
<ul>
<li>Active</li>
<li>Inactive</li>
<li>Recently Active</li>
<li>Upgrade Available</li>
</ul>
<p>WordPress 2.8 brings some great new features to the table &#8211; some major and others minor &#8211; but they&#8217;re changes that make using WordPress more efficient, convenient and reliable. Keep an eye out for WordPress 2.9 and beyond as it evolves into what could be one of the best Content-Management-Systems available!</p>
<ul class="webroundup">
<li>Follow us on <a href="http://www.twitter.com/nettuts">Twitter</a>, or subscribe to the <a href="http://feeds.feedburner.com/nettuts" title="NETTUTS RSS Feed">NETTUTS RSS Feed</a> for more daily web development tuts and articles.</li>
</ul>
<p>
<script type="text/javascript"><!--digg_url = "post permalink (not digg url)"; // -->
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/10-wordpress-28-features-to-look-out-for/feed/</wfw:commentRss>
		<slash:comments>65</slash:comments>
		</item>
		<item>
		<title>How to Set Up a Killer WordPress Testing Environment Locally</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/how-to-set-up-a-killer-wordpress-testing-environment-locally/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/how-to-set-up-a-killer-wordpress-testing-environment-locally/#comments</comments>
		<pubDate>Thu, 21 May 2009 14:51:15 +0000</pubDate>
		<dc:creator>Harley</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress mu]]></category>
		<category><![CDATA[wordpress testing environment]]></category>
		<category><![CDATA[wp]]></category>

		<guid isPermaLink="false">http://net.tutsplus.com/?p=5065</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/200x200.png" alt="How to Set Up a Killer WordPress Testing Environment Locally" />]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a heavy WordPress developer like me, you might find that you need to create a new installation for each site that requires a strange structure or specific posts, instead of using your uniform local test WordPress installation. Cue WordPress Mu. WordPress Multi User is a platform created by the geniuses at Automattic that is basically a WordPress installation that allows multiple blogs to run using the same software.</p>
<p><span id="more-5065"></span></p>
<p>In this tutorial, I&#8217;m going to show you how to set up WordPress Mu locally so that it can be viewed in VMWare Fusion too, a piece of software that allows for cross-browser testing on Microsoft XP and Vista. Mac only, sorry, however I&#8217;m sure something similar can be done with the PC versions of MAMP.</p>
<p><!--more--></p>
<h3>Preface</h3>
<p>Unfortunately this tutorial requires a few paid things, so it can get expensive. You&#8217;ll need <a href="http://www.mamp.info/en/mamp-pro/index.html">MAMP PRO</a>, Microsoft XP and <a href="http://www.vmware.com/products/fusion">VMWare Fusion</a>- Only MAMP PRO is essential if you don&#8217;t need to cross-browser test. MAMP PRO has some functionality on MAMP that we need when defining our new developer site. Download <a href="http://mu.wordpress.org">WordPress MU</a> as well, we&#8217;ll need that!</p>
<p><strong>Note:</strong> MAMP PRO comes with MAMP- just stick both of them in Applications because you need the two.</p>
<h3>Run Down</h3>
<p>OK, so if you don&#8217;t know completely what we&#8217;ll be doing, I&#8217;m going to break it down further. If you use WordPress to develop your websites, then each time you create a new website you need to download a new installation of WordPress, install it, and go through that entire process just for a new site. This takes time AND hard drive space. What we&#8217;ll be doing, is setting up a type of WordPress installation that allows you to use the same WordPress files, and set up a new WordPress site via wp-admin instead of going through the famous 5 minute install.</p>
<p>At the end of the tutorial you&#8217;ll be able to visit http://wordpress.mu/ to see your local WordPress MU installation. You&#8217;ll also be able to open the same page in VMWare Fusion, which will be running Windows XP. This means you&#8217;ll be able to see it in ALL major browsers- IE5.5-8, Chrome, Safari Mac, Safari PC, Firefox Mac, Firefox PC, etc. The list goes on.</p>
<h3>Step 1 &#8211; Changing Ports on MAMP PRO</h3>
<p>Once you&#8217;ve installed MAMP PRO, open it up and the servers should start running. We need to change the ports. Ports are basically the &#8216;door&#8217; that a server tells the browser to go through. You might be familiar with CPanelX&#8217;s port <code>8082</code>. CPanel has told your server that to get to the CPanel, you need to go through door <code>8082</code>. By default, MAMP PRO likes to have it&#8217;s own ports- <code>8888</code> for apache and <code>8889</code> for MySQL. We need to change this back to the default settings. You can either turn it to <code>80 / 3306</code> manually or simply click &#8216;Default Ports&#8217;</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/change-ports.png" alt="" /></div>
<p>MAMP PRO will then tell you that the servers need to restart in order for changes to take effect. Click OK and let it do it&#8217;s thing. If it tells you that Apache&#8217;s failing to restart, check that &#8216;Web Sharing&#8217; is un-ticked in your Sharing Prefs pane. You should now be able to visit <code>http://localhost:80</code> to see either the &#8216;If you can see this page Apache is successfully installed&#8217; page or the default MAMP index page. Great.</p>
<h3>Step 2 &#8211; editing httpd.conf</h3>
<p>httpd.conf is what Apache reads when it looks at what hosts or URLs to run on. You can find httpd.conf in <code>~/Applications/MAMP/conf/apache/httpd.conf</code></p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/httpd.conf.png" alt="" /></div>
<p>Scroll down to the very bottom, and you will probably find this:</p>
<pre name="code" class="html">&lt;VirtualHost *>
	DocumentRoot "/Applications/MAMP/htdocs"
	ServerName localhost
&lt;/VirtualHost></pre>
<p>or nothing at all. We are going to add this, or change it to the following code. We&#8217;ll also be adding our own Virtual Host, which will be wordpress.mu (Just a side note, when doing this it&#8217;s important to never pick a URL that will conflict with an actual site, because while the settings are like you&#8217;ll never be able to visit your local site&#8217;s url online. e.g. if I set my host to be example.com, example.com would <strong>always</strong> resolve to my local machine as opposed to example.com online). So like I said, add this (or change the default one)</p>
<pre name="code" class="html">&lt;VirtualHost *>
	DocumentRoot "/Users/YOU/wordpres.mu"
	ServerName localhost
&lt;/VirtualHost>

&lt;VirtualHost *>
	DocumentRoot "/Users/YOU/Sites/wordpress.mu"
	ServerName http://wordpress.mu/
&lt;/VirtualHost></pre>
<p>Don&#8217;t forget to change YOU to your user name. This will also require a restart of the Apache and MySQL servers. You&#8217;ll probably notice that wordpress.mu doesn&#8217;t exist in your sites folder- so create it!</p>
<h3>Step 3 &#8211; editing /etc/hosts</h3>
<p>This file, <code>hosts</code> is the configuration for exactly that, the hosts. So httpd.conf set the hosts for your mac! This requires some Terminal work, but I promise you it&#8217;s as easy as copying and pasting the command, and then typing a single line!</p>
<p>Open Terminal (it&#8217;s in Utilities in the Applications folder) and type:</p>
<pre name="code" class="html">sudo pico /etc/hosts</pre>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/terminal-sudo-pico.png" alt="" /></div>
<p>And hit enter. sudo means it&#8217;s an admin action, pico is the Terminal&#8217;s editor (which you&#8217;ll soon see) and /etc/hosts is the path to what we want to edit. You&#8217;ll be prompted for your password, so type it in. You should now see this screen:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/pico-edit.png" alt="" /></div>
<p>That last line may or may not be there- if it isn&#8217;t don&#8217;t worry we&#8217;ll be changing it anyway. Put the cursor at the bottom (clicking doesn&#8217;t work) and where that last line of code is, change localhost to wordpress.mu. It should read:</p>
<pre name="code" class="html">127.0.0.1 wordpress.mu</pre>
<p>127.0.0.1 is the computer&#8217;s way of saying &#8216;me&#8217;. Save the file by pressing <code>ctrl+o</code> (o for write <strong>out</strong> and then <code>ctrl+x</code> to quit pico.</p>
<h3>Step 4 &#8211; Adding a host for MAMP PRO</h3>
<p>The final piece of the puzzle is to create a host alias in MAMP PRO. Now that the hosts are all set up, we need to tell MAMP PRO that it&#8217;s actually there. In MAMP PRO click on the &#8216;Hosts&#8217; tab. You need to add an alias. Click the little plus in the bottom left. You need to set a few things. Server name: <code>wordpress.mu</code>, port: <code>80</code>, Disk Location: <code>/Users/YOU/Sites/wordpress.mu</code>, and add an alias in the bottom right of <code>wordpress.mu</code>.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/add-alias.png" alt="" /></div>
<p>Click apply, and once again restart the servers</p>
<h3>Step 5 &#8211; WordPress MU</h3>
<p>Grab your wordpress-mu Download and rename it to wordpress.mu. Stick it in your sites folder. Hey presto, you can go through with the installation! Unfortunately I found no easy way to use sub-domains on a local server, so I just stuck to sub-folders as the structure. Great! You can now use WordPress mu on your local computer! Go ahead with the 5 minute install, and then you can add blogs under the &#8216;Admin Menu&#8217;. I wont go too much into the actual functionality of WPMU, but I&#8217;ll explain how I use when working at the end.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/wpmu-install.png" alt="" /></div>
<h3>VMWare Fusion</h3>
<p>I&#8217;m not going to go into depth on this topic, because there are <a href="http://macinstruct.com/node/248">many</a> <a href="http://askdavetaylor.com/how_do_i_install_microsoft_vista_vmware_fusion_mac_os_x.html">tutorials</a> <a href="http://moourl.com/b41g9">on</a> it. I will however explain how to modify a brand new installation (even if you&#8217;ve used it for ages there probably isn&#8217;t a lot that will have changed anyway). Start up VMWare Fusion, and activate Unity if you so please. Unity allows you to run Windows XP windows natively in your mac- see screenshot below!</p>
<div class="tutorial_image"><a href="res/unity.png"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/unity-small.png" alt="" /></a></div>
<h3>Step 6 &#8211; \etc\hosts (windows)</h3>
<p>The <code>/etc/hosts</code> file in XP needs editing too. You can find it in <code>C:\Windows\system32\drivers\etc\hosts</code>. Open it up with Notepad, and we&#8217;re about to put our line in. We need to grab an IP address first. Open a new terminal window and type <code>ifconfig -a</code>. You will get a whole lot of junk back- scroll down a bit until you can see &#8216;vmnet8&#8242;. Grab that IP address, the one I&#8217;ve highlighted in the image below.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/ifconfig-a.png" alt="" /></div>
<p>Then go back to your \etc\hosts file in windows, and at the bottom, paste that IP address in followed by <code>wordpress.mu</code>.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/edit-hosts.png" alt="" /></div>
<h3>Step 7 &#8211; flushdns</h3>
<p>Sadly, windows needs to be slapped for it to noticed that a change has taken place, so you now need to open Command Prompt. It is in Accessories in the start menu. Simply type <code>ipconfig /flushdns</code>. What this does is flush all the DNS names (localhost mainly) so that it recognises the updated hosts file.</p>
<h3>Voila!</h3>
<p>You are now able to visit your MAMP running WordPress MU installation on every windows browser there was- looks like I have a bit of work to do!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/ie6.png" alt="" /></div>
<h3>A practical use for it</h3>
<p>So as promised, I said I&#8217;d tell you how I use it. What I&#8217;ve done is gone ahead and downloaded every browser I need/support and installed it into my XP install. This way I can compare my WordPress sites window beside window and easily have access to modify whatever I need to, without having to save it and refresh an online installation!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/browsers.png" alt="" /></div>
<div class="tutorial_image"><a href="res/side-by-side.png"><img src="http://nettuts.s3.amazonaws.com/331_ultimateWP/res/side-by-side-small.png" alt="" /></a></div>
<h3>Take a Wrap</h3>
<p>So there you have it. The ultimate guide to the ultimate WordPress setup. It feels like I haven&#8217;t put enough emphasis on WordPress MU itself, but it is just an install tutorial. WordPress MU saves loads and loads of disk space by taking all your separate WordPress blogs and putting them into 1- you have a universal theme folder/manager which makes it super easy to quickly swap between editing sites.</p>
<ul class="webroundup">
<li>Follow us on <a href="http://www.twitter.com/nettuts">Twitter</a>, or subscribe to the <a href="http://feeds.feedburner.com/nettuts" title="NETTUTS RSS Feed">NETTUTS RSS Feed</a> for more daily web development tuts and articles.</li>
</ul>
<p>
<script type="text/javascript"><!--digg_url = "post permalink (not digg url)"; // -->
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/how-to-set-up-a-killer-wordpress-testing-environment-locally/feed/</wfw:commentRss>
		<slash:comments>112</slash:comments>
		</item>
		<item>
		<title>Dissecting the WordPress Text Widget</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/dissecting-the-wordpress-text-widget/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/dissecting-the-wordpress-text-widget/#comments</comments>
		<pubDate>Thu, 07 May 2009 09:20:47 +0000</pubDate>
		<dc:creator>Jarkko Laine</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://net.tutsplus.com/?p=4720</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/311_WordpressWidget/200x200.png" alt="Dissecting the WordPress Text Widget" />]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we will take a close look under the hood of the WordPress text widget to uncover the process of <strong>creating a widget</strong> that can be added to multiple widget locations. </p>
<p><span id="more-4720"></span></p>
<h3>The Problem</h3>
<p>If you know the basics of programming in PHP, creating a WordPress widget is not difficult at all. I have covered the basics in an earlier tutorial, <a href="http://nettuts.com/tutorials/wordpress/anatomy-of-a-wordpress-plugin/">The Anatomy of a WordPress Plugin</a> &#8212; it&#8217;s a good idea to check that one out before reading any further, if you haven&#8217;t built a widget before.</p>
<p>While that basic way of creating a widget is good enough for many plugins, it has one major drawback: the widget can be added to only one slot in a blog. </p>
<blockquote><p>If you add the widget to one of the sidebars, the widget&#8217;s &#8220;Add&#8221; button disappears and the widget cannot be added to any other slot before removing it from the first one. </p></blockquote>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/311_WordpressWidget/2.jpg" border="0"/><br />
Notice how the &#8220;Archives&#8221; widget cannot be added anymore.</div>
<p>In some cases, that&#8217;s not a problem, because the nature of the widget is that it&#8217;s shown only once. For example, it&#8217;s quite OK to only list the blog archive in one place in the layout. But there are many cases where more than one instance can be very useful. One such example is the Text widget that comes bundled with WordPress. </p>
<p>The Text widget is a simple widget that lets you specify a header and a text, also allowing HTML, and renders its contents to the blog&#8217;s sidebar. Because of this simplicity, the widget can be used for a wide range of purposes. For example, in the next image &#8212; a screenshot from my personal blog &#8212; you can see how I use the text widget in my sidebar first to show a welcome text, and then again to show some ads at the bottom of the sidebar. In WordPress documentation, widgets like this are called <em>&#8220;multi-widgets.&#8221;</em></p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/311_WordpressWidget/3.jpg" border="0" /></div>
<h4>But How Do You Create Your Own Multi-Widget?</h4>
<p>Because WordPress is an open source project, we can dig into the source code and use it as a reference for our own projects. For this tutorial, it means that we can take a closer look at the Text widget and see how it has been implemented, using it as an example for turning our own widgets into multi-widgets.</p>
<h3>Step 1: Locating the WordPress Text Widget</h3>
<p>The first step is to search through the WordPress codebase and locate the text widget. It&#8217;s an interesting step and I recommend you check out some other files here and there too to gain an overall glimpse of what goes on inside of the blogging platform.</p>
<p>But if you just can&#8217;t wait to get to action, here&#8217;s where you will find the widget code:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/311_WordpressWidget/1.jpg" border="0" /><br />
The widget code is located in <strong><code>wordpress/wp-includes/widgets.php</code></strong></div>
<p>Open the file and scroll down to the very end of it, around line 1958 (in version 2.7.1), and there, hidden in the middle of the source code, <strong>you&#8217;ll find an example widget, commented out and labeled &#8220;Pattern for multi-widget (allows multiple instances such as the text widget).&#8221;</strong> </p>
<p>At first, the example code can look rather daunting, so we&#8217;ll go through it line by line, making sense of the ideas around which the pattern is built. The code snippets in this tutorial have been copied from the example pattern, but I have made a few small changes here and there to make the code easier to follow (mainly splitting long lines to shorter ones). Apart from those small adjustments, the source code is exactly the same as you&#8217;ll find by opening <strong><code>widgets.php</code></strong> from the WordPress codebase.</p>
<h3>Step 2: Understanding Widget Data</h3>
<p>When the user presses the &#8220;Save Changes&#8221; button in the Widgets menu, WordPress collects the form parameters from each widget listed in the sidebars and sends them to each of the registered widgets. This feature is what makes creating multi-widgets possible: As the widget controller function gets notified to save a widget instance, all the parameters are passed to it, and it can update every instance of this widget type at one go, adding new ones and removing unused ones as needed.</p>
<p>We will look into the details of the saving process in a short while, but first, a good place to start looking at how the widget data for a multi-widget are stored is to look at the part of the code where the data are used. Here is the code for the method used for showing an instance of the example widget:</p>
<pre name="code" class="php">&lt;?php
function widget_many( $args, $widget_args = 1 ) {
	extract( $args, EXTR_SKIP );
	if ( is_numeric($widget_args) )
		$widget_args = array( 'number' =&gt; $widget_args );
	$widget_args = wp_parse_args( $widget_args, array( 'number' =&gt; -1 ) );
	extract( $widget_args, EXTR_SKIP );

	// Data should be stored as array
	$options = get_option('widget_many');
	if ( !isset($options[$number]) )
		return;

	echo $before_widget;

	// Do stuff for this widget, drawing data from $options[$number]

	echo $after_widget;
}
?&gt;</pre>
<ol>
<li>
<p>The first parameter passed to the widget rendering function, <strong><code>$args</code></strong>, contains generic widget settings, such as what should be printed before and after the widget, and how the widget heading should be formatted. The code on line 3 is used to split that information into local variables, from which <strong><code>$before_widget</code></strong> and <strong><code>$after_widget</code></strong> are used in the example.</p>
</li>
<li>
<p>The second parameter, <strong><code>$widget_args</code></strong> is more interesting to us: it contains the id of the widget instance to be rendered. Lines 4 to 7 are there to make sure the parameter comes in a correct format, and that in the end, after the <strong><code>extract</code></strong> call on line 7, we can find the widget index in the local variable <strong><code>$number</code></strong>.</p>
</li>
<li>
<p>Just like widget settings for a simple, one-time-only widget, the settings for a widget instance are stored as an array containing key-value pairs for each setting. But as we now need to store multiple instances, instead of saving each array with its own call to <strong><code>update_option</code></strong>, we put them all in one array using the instance id (<strong><code>$number</code></strong>) as the index and then save the whole thing with the id of the widget type.</p>
</li>
<li>
<p>In the above example, we have a widget named &#8220;<strong><code>widget_many</code></strong>&#8220;, and let&#8217;s say we have added three instances of it to our blog sidebar. When rendering one of them, we first get an array containing all of the <strong><code>widget_many</code></strong> instances by calling <strong><code>get_option('widget_many');</code></strong> (line 10) and then find the data for the current instance from that array (line 16).</p>
</li>
</ol>
<p>The example code from doesn&#8217;t show the specifics of what you should do with the data, so let&#8217;s look at the actual text widget for more insight:</p>
<pre name="code" class="php">&lt;?php
function wp_widget_text($args, $widget_args = 1) {
	extract( $args, EXTR_SKIP );
	if ( is_numeric($widget_args) )
		$widget_args = array( 'number' =&gt; $widget_args );
	$widget_args = wp_parse_args( $widget_args, array( 'number' =&gt; -1 ) );
	extract( $widget_args, EXTR_SKIP );

	$options = get_option('widget_text');
	if ( !isset($options[$number]) )
		return;

	$title = apply_filters('widget_title', $options[$number]['title']);
	$text = apply_filters( 'widget_text', $options[$number]['text'] );
?&gt;
		&lt;?php echo $before_widget; ?&gt;
			&lt;?php
				if ( !empty( $title ) ) {
					echo $before_title . $title . $after_title;
				}
			?&gt;
			&lt;div class="textwidget"&gt;&lt;?php echo $text; ?&gt;&lt;/div&gt;
		&lt;?php echo $after_widget; ?&gt;
&lt;?php
}
?&gt;</pre>
<p>On lines 13 and 14, you can see how the two parameters needed for the text widget are read from the options using <strong><code>$number</code></strong> as instance id. And on the next ten lines, the parameters are rendered on the screen.</p>
<h3>Step 3: Saving Widget Settings</h3>
<p>By analyzing the widget rendering function, we have now uncovered the basics behind saving the data for a multi-widget:</p>
<ol>
<li>Save the data of the specific widget instance to an array with setting names (for example &#8220;title&#8221;) as keys</li>
<li>Save all widget instances into an array using the instance ids as keys</li>
<li>Save the whole thing to the database using WordPress&#8217;s built-in <a href="http://codex.wordpress.org/Function_Reference/get_option">get_option</a> / <a href="http://codex.wordpress.org/Function_Reference/update_option">update_option</a> system.</li>
</ol>
<p>Now, we&#8217;ll look closer and see the tricks and caveats involved.</p>
<p>Using the same approach as before, we will now look into the function used for showing and handling the settings forms and go through it line by line. This function, <strong><code>widget_many_control</code></strong>, is the function that saves the settings and renders the settings form for the &#8220;widget_many&#8221; example widget. It is called once for each <code><strong>widget_many</strong></code> instance, always passing the instance id in <strong><code>$widget_args</code></strong>.</p>
<p>As the function is a part of the form submission handling, the <strong><code>$_POST</code></strong> array will contain all parameters that have been sent using the widget editing form.</p>
<pre name="code" class="php">&lt;?php
function widget_many_control( $widget_args = 1 ) {
	global $wp_registered_widgets;
	static $updated = false;

	if ( is_numeric($widget_args) )
		$widget_args = array( 'number' =&gt; $widget_args );
	$widget_args = wp_parse_args( $widget_args, array( 'number' =&gt; -1 ) );
	extract( $widget_args, EXTR_SKIP );</pre>
<p>On the first lines of the function, you&#8217;ll see something familiar (lines 6-9). This is the same piece of code that was used in the rendering function to make sure <strong><code>$number</code></strong> has been initialized with the numerical id of the current widget instance.</p>
<p>But as you&#8217;ll soon notice, we won&#8217;t need that index for anything else than rendering the widget editing form, as we always save every instance of the &#8220;widget_many&#8221; widget type in one loop.</p>
<p>Next, we&#8217;ll retrieve the current widget settings, creating them if they don&#8217;t exist:</p>
<pre name="code" class="php">
	$options = get_option('widget_many');
	if ( !is_array($options) )
		$options = array();</pre>
<p>When implementing your own widget, remember to change the key, <strong><code>widget_many</code></strong> to your own widget&#8217;s id. Apart from that, this code can be reused as is. On lines 2 and 3, the code takes care of the case when we are adding the first widget instance of this type by creating an empty options array to use.</p>
<p>If settings have already been saved at least for one instance, we get them from <strong><code>get_option</code></strong> and can go on updating the settings if a form was submitted:</p>
<pre name="code" class="php">		if ( !$updated &amp;&amp; !empty($_POST['sidebar']) ) {</pre>
<p>The above line has two functions: It checks if data was posted (&#8221;<strong><code>!empty($_POST['sidebar'])</code></strong>&#8220;) and makes sure that instances of this widget type are handled only once.</p>
<p>The widget system calls the widget handling function once per each widget instance, but because we need to take care of things like adding and removing new widget instances, we can&#8217;t do that without knowing all the widgets of this type that exist. This is why the approach is to update every widget instance of this type on the first occurrence, and then set the global variable <strong><code>$updated</code></strong> to true so that the next instance will not do the updating again.</p>
<pre name="code" class="php">// Tells us what sidebar to put the data in
$sidebar = (string) $_POST['sidebar'];

$sidebars_widgets = wp_get_sidebars_widgets();
if ( isset($sidebars_widgets[$sidebar]) )
	$this_sidebar =&amp; $sidebars_widgets[$sidebar];
else
	$this_sidebar = array();

foreach ( $this_sidebar as $_widget_id ) {
	$widget = $wp_registered_widgets[$_widget_id];
	if ( 'widget_many' == $widget['callback']
		&amp;&amp; isset($widget['params'][0]['number']) ) {
			$widget_number = $widget['params'][0]['number'];

			if ( !in_array( "many-$widget_number", $_POST['widget-id'] ) )
				unset($options[$widget_number]);
	}
}

// Compile data from $widget_many_instance
$widget_data = (array) $_POST['widget-many'];
foreach ( $widget_data as $widget_number =&gt; $widget_many_instance ) {
	if ( !isset($widget_many_instance['something'])
		&amp;&amp; isset($options[$widget_number]) ) {
			// user clicked cancel
			continue;
	}
	$something = wp_specialchars( $widget_many_instance['something'] );
	$options[$widget_number] = array( 'something' =&gt; $something );
}

update_option('widget_many', $options);

$updated = true; // So that we don't go through this more than once</pre>
<p>This code snippet first looks up all the widgets stored in the sidebar that is being updated (lines 2-8) and then goes through the list removing all that match the widget id of this widget type (lines 10-18). </p>
<p><strong><code>$_POST("sidebar")</code></strong> (line 2) contains the id of the sidebar. This way, if the user has removed a widget, it will be deleted from the data as well. And by deleting everything, we make sure we don&#8217;t accidentally leave duplicates, for example if the id of some widget has changed between updates.</p>
<p>After removing everything, we start adding the widgets that were posted by the user. In the posted form, there is an array containing all the data for every instance of the widget type. The array is organized like this:</p>
<pre name="code" class="php">	['widget-many'] =&gt;
		[0] =&gt; params for widget instance 0 (array),
		[1] =&gt; params for widget instance 1 (array),
		...</pre>
<p>On lines 23-31, the code loops over the widget instance data submitted and creates the settings for each instance (lines 29 and 30). As this is just example code, the saving part is using placeholder data such as &#8220;something&#8221;. So, let&#8217;s again take a look at the text widget to see how this works with real data:</p>
<pre name="code" class="php">$title = strip_tags(stripslashes($widget_text['title']));
if ( current_user_can('unfiltered_html') )
	$text = stripslashes( $widget_text['text'] );
else
	$text = stripslashes(wp_filter_post_kses( $widget_text['text'] ));
$options[$widget_number] = compact( 'title', 'text' );</pre>
<p>
The text widget has two parameters: <strong><code>title</code></strong> and <strong><code>text</code></strong>. The <strong><code>$widget_text</code></strong> variable in this piece of code is used the same way as <strong><code>$widget_many_instance</code></strong> in the example code we have been following: it holds the data posted for a specific instance of the widget.</p>
<p>In the text widget example, you&#8217;ll also see some interesting security features that you may want to look into a bit more when developing your own widgets. For this tutorial, however, it is enough to see that the contents of the variables <strong><code>$title</code></strong> and <strong><code>$text</code></strong> are read from the array posted and then stored as an array to the widget&#8217;s options on line 6.</p>
<p>If you are wondering about the <strong><code>compact()</code></strong> function, it&#8217;s the opposite of <strong><code>extract()</code></strong>, and takes the local variables whose names were passed as parameters and turns them into an array with the names as keys.</p>
<p>Finally, the new <strong><code>$options</code></strong> array is stored as the data for the widget, <strong><code>widget_many</code></strong> in the example code or <strong><code>widget_text</code></strong> in the text widget, using the <strong><code>update_option()</code></strong> function.</p>
<p>The last thing remaining in the widget settings function is drawing the form for this widget instance. This form is not rendered on screen as is, but WordPress converts it into a real form later, using some JavaScript magic. The code below is from the template code, so it uses <strong><code>$something</code></strong> to represent the widget data. In the text widget it is replaced by <strong><code>$title</code></strong> and <strong><code>$text</code></strong>, and in your own widget with anything you need to save.</p>
<p>It&#8217;s important to notice that although the saving is done for every instance at one go, the form rendered here is for just one instance. This is where we&#8217;ll use the widget instance id read in at the beginning of the function.</p>
<pre name="code" class="php">	if ( -1 == $number ) {
		$something = '';
		$number = '%i%';
	} else {
		$something = attribute_escape($options[$number]['something']);
	}</pre>
<p>On the above lines, the widget first checks if a valid widget number was given or not. If not, and <strong><code>$number</code></strong> was set to the default value, -1, all data should be set to default values. Otherwise, we will get the data from the <strong><code>$options</code></strong> array and use it to populate the form with current settings. This is a nice thing to do so that the user won&#8217;t have to always start editing the widget from an empty slate.</p>
<p>And then, the form itself is built so that it can be read into an array when posted to the widget handling code: The form inputs are named following the pattern <strong><code>widget-many[$number][something]</code></strong> where <strong><code>$number</code></strong> is the number of this widget instance and <strong><code>something</code></strong> is the name of the parameter to be saved. WordPress then parses this into the array structure described earlier when the user submits the form.</p>
<p>The form doesn&#8217;t have a submit button because all the widgets are saved using the same submit button provided by WordPress.</p>
<pre name="code" class="php">&lt;p&gt;
	&lt;input class="widefat"
		id="widget-many-something-&lt;?php echo $number; ?&gt;"
		name="widget-many[&lt;?php echo $number; ?&gt;][something]"
		type="text" value="&lt;?php echo $data; ?&gt;" /&gt;
	&lt;input type="hidden"
		id="widget-many-submit-&lt;?php echo $number; ?&gt;"
		name="widget-many[&lt;?php echo $number; ?&gt;][submit]" value="1" /&gt;
&lt;/p&gt;</pre>
<h3>Step 4: Registering the Widget as Multi-Widget</h3>
<p>For WordPress to show a widget in the widget list, you need to register it by telling WordPress what functions to use for rendering the widget and its settings form. The way this is done for multi-widgets isn&#8217;t that different from regular widgets. The only difference is in how the id of the widget is defined: In <strong><code>$control_ops</code></strong> (line 7), we tell WordPress to enable multiple instances and to attach all widget instances with an id starting <strong><code>"many"</code></strong> to this widget type.</p>
<pre name="code" class="php">function widget_many_register() {
	if ( !$options = get_option('widget_many') )
		$options = array();

	$widget_ops = array('classname' =&gt; 'widget_many',
                'description' =&gt; __('Widget which allows multiple instances'));
	$control_ops = array('width' =&gt; 400, 'height' =&gt; 350, 'id_base' =&gt; 'many');
	$name = __('Many');

	$registered = false;
	foreach ( array_keys($options) as $o ) {
		// Old widgets can have null values for some reason
		if ( !isset($options[$o]['something']) )
			continue;

		// $id should look like {$id_base}-{$o}
		$id = "many-$o"; // Never never never translate an id
		$registered = true;
		wp_register_sidebar_widget( $id, $name, 'widget_many',
                        $widget_ops, array( 'number' =&gt; $o ) );
		wp_register_widget_control( $id, $name, 'widget_many_control',
                        $control_ops, array( 'number' =&gt; $o ) );
	}

	// If there are none, we register the widget's
    // existance with a generic template
	if ( !$registered ) {
		wp_register_sidebar_widget( 'many-1', $name, 'widget_many',
                $widget_ops, array( 'number' =&gt; -1 ) );
		wp_register_widget_control( 'many-1', $name, 'widget_many_control',
                $control_ops, array( 'number' =&gt; -1 ) );
	}
}

// This is important
add_action( 'widgets_init', 'widget_many_register' );</pre>
<p>In the function above, we first register all the existing widgets of this type, skipping the ones that don&#8217;t have valid data (lines 11-23), and then if there is no instance available yet, register a default one to make sure the widget is registered and available in the sidebar (lines 27-32).</p>
<p>As the last, crucial step, on line 34, we hook the widget initialization function to the <strong><code>widgets_init</code></strong> event so that WordPress will call it when it is the time to initialize all widgets. Without this function, we wouldn&#8217;t see any of the functionality of the widget we just analyzed as no part of the code would ever get called.</p>
<h3>Step 5: Putting it All Together</h3>
<p>In the snippets above, I have deliberately left out some of the code to make things more readable, so you won&#8217;t be able to just copy the pieces and put them together. Instead, you should go and copy that same code from your WordPress installation.</p>
<p>After that, you just need to put in your own functionality, and there you have it: your own multi-widget.</p>
<ul class="webroundup">
<li>Follow us on <a href="http://www.twitter.com/nettuts">Twitter</a>, or subscribe to the <a href="http://feeds.feedburner.com/nettuts" title="NETTUTS RSS Feed">NETTUTS RSS Feed</a> for more daily web development tuts and articles.</li>
</ul>
<p>
<script type="text/javascript"><!--digg_url = "post permalink (not digg url)"; // -->
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/dissecting-the-wordpress-text-widget/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Social Networking with BuddyPress</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/social-networking-with-buddypress/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/social-networking-with-buddypress/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 10:30:14 +0000</pubDate>
		<dc:creator>Justin Shreve</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://net.tutsplus.com/?p=4017</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/263_buddypress/200x200.png" alt="An Introduction to BuddyPress" />]]></description>
			<content:encoded><![CDATA[<p>Automattic, the company behind WordPress, has recently acquired and will be releasing social networking software called BuddyPress. The software, built on top of WordPress, was created by Andy Peatling as way to start  your very own social network similar to Facebook. Today, we will take a look at installing BuddyPress.<span id="more-4017"></span>
</p>
<p><!--more--></p>
<h3>Step 1 &#8211; What is BuddyPress?</h3>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/buddypressintro.png" alt="BuddyPress" style="width: 379px;" />
</div>
<p>BuddyPress is a social networking application  built on top of WordPress Multi-User (MU) as a plugin. WordPress MU is the the software behind <a href="http://wordpress.com">WordPress.com</a>. It allows  a user to host a network of blogs on a site. BuddyPress adds a large variety of new social interaction features to WordPress. The features can be added all at once or as individual components:</p>
<ul>
<li>A WordPress blog</li>
<li>Individual profiles for members</li>
<li>Private Message (PM) functionality</li>
<li>Friend Networks</li>
<li>Groups, which include a blog, photos and other user generated content</li>
<li>&quot;The Wire&quot; (like the wall on Facebook)</li>
<li>Activity/Action streams of public actions on the site</li>
<li>Forums using bbPress</li>
</ul>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/features.png" alt="Features" style="width: 157px;" />
</div>
<p>A <a href="http://buddypress.org/demo/">fully featured demo</a> is available at the BuddyPress website.</p>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/demo.png" alt="Demo" style="width: 384px;" />
</div>
<p>Today, we will install a full installation of BuddyPress (all the bells and whistles), so we can start a social network from scratch.</p>
<p>The software is in its RC stage, but is nearing its final version. The current version  will help you get started with social networking by providing an  admin control panel and all the basic features outlined above. You will then be ready to upgrade to the final version when the time comes.</p>
<h3>Step 2 &#8211; Requirements</h3>
<p>Before you install the BuddyPress system, your server will require you have two components already in place:</p>
<ul>
<li> a <a href="http://net.tutsplus.com/tutorials/php/everything-you-need-to-get-started-with-mysql/">MySQL database</a> to store all the BuddyPress information. If you do not have a database created, create one with a user who has all privileges (such as UPDATE, INSERT, DELETE, SELECT) on that database. Remember the username/password and database name for later steps.</li>
<li> a <a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">mod rewrite module</a> so you can have clean URLS. If you have used WordPress or another piece of software that has clean URLs, then you should be ready to proceed without adding this component again.</li>
</ul>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/phpmyadmin.png" alt="phpMyAdmin" style="width: 557px;" />
</div>
<h3>Step 3 &#8211; Download WordPress MU</h3>
<p>Before you can start the BuddyPress installation you will need a copy of WordPress MU installed.  Grab the <a href="http://mu.wordpress.org/latest.zip">latest version (ZIP)</a> (<a href="http://mu.wordpress.org/latest.tar.gz">TAR.GZ</a>) and unzip it. You should see a folder with a name similar to &quot;wordpress-mu&quot;.</p>
<p>Upload the files in this directory to the location where you want to access your site. This can be the main domain or a subfolder. Grab a cup of coffee or tea while you wait for the upload to finish.</p>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/ftp.png" alt="FTP/Files" style="width: 313px;" />
</div>
<h3>Step 4 &#8211; Install WordPress MU</h3>
<p>Once the upload has completed you can go ahead and install WordPress MU.</p>
<p>Point your browser to the directory where you uploaded the files so that index.php is executed. You will be shown a screen to enter some details. The settings should be filled as given below:</p>
<ul>
<li><strong>Blog Addresses</strong> &#8211; For the purpose of this article we will select &quot;sub-directories&quot;. If you happen to have Wildcard DNS records enabled, you can select the other option, but that is outside the scope of this article.</li>
<li><strong>Database Name</strong> &#8211; The database name from Step 2</li>
<li><strong>User Name</strong> &#8211; The username from Step 2</li>
<li><strong>Password</strong> &#8211; The password from Step 2</li>
<li><strong>Database Host</strong> &#8211; This is usually localhost if the MySQL server is on the same server as the web server. Only change this if the installation is returning errors about the server/host setting.</li>
<li><strong>Server Address</strong> &#8211; The installer should be able to guess this setting, but double check that it is set to the  server/domain you are installing to.</li>
<li><strong>Site Title</strong> &#8211; This will be the name of the social network site, so name it whatever you want.</li>
<li><strong>Email</strong> &#8211; Enter a valid email address to be used for the admin account.</li>
</ul>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/wordpress-mu.png" alt="Install" style="width: 528px;" />
</div>
<p>Once you have double-checked all the above settings, click Submit. If all goes well, you should be greeted with an &quot;Installation Finished!&quot; screen that includes your username and password. You have also been sent an email with the same details included.</p>
<p>Before you continue, follow the instructions for setting permissions on the Installation Finished page.</p>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/install.png" alt="Install" style="width: 374px;" />
</div>
<h3>Step 5 &#8211; Download BuddyPress</h3>
<p>At this point, you can now install the BuddyPress system. Since we are installing the full system, you can download the &quot;combo&quot; archive <a href="http://buddypress.org/download/combo/latest.zip">here</a>.</p>
<p>Unzip the combo file and upload all the contents of the extracted zip to the root mu-plugins folder located in wp-content. Upload ALL the folders and files located in the zip, and make sure these folders and files have been chmodded to 755.</p>
<p>Move the mu-plugins/bp-themes folder you just uploaded to wp-content. Make sure these folders have been chmodded to 755.</p>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/mu-plugins.png" alt="Files" style="width: 394px;" />
</div>
<h3>Step 6 &#8211; Setup BuddyPress</h3>
<p>Once the files are uploaded, log in to the WordPress MU admin control panel with  the username and password you created earlier. The URL to log in (emailed to you when you installed WordPress MU) is in the form <a href="http://yourdomain.tld/folder/wp-login.php">http://yourdomain.tld/folder/<WBR>wp-login.php</a></p>
<p>Under the &quot;Site Admin&quot; menu find the &quot;Themes&quot; link and click it. You will be shown a list of installed WordPress MU themes, one of which is the BuddyPress theme. Select &quot;Yes&quot; for &quot;BuddyPress Home Theme&quot; and click &quot;Update Themes&quot;.</p>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/themes.png" alt="Themes" style="width: 492px;" />
</div>
<p>Finally, you will need to enable registrations if you want users to be able to sign up for your site. Under the &quot;Site Admin&quot; menu go to &quot;Options&quot; and make sure the Enabled option is selected for &quot;Allow new registrations&quot;.</p>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/allownewreg.png" alt="Allow New Registration Settings" style="width: 519px;" />
</div>
<p>Congratulations! Your social network is now ready for use. When logged into the admin control panel, you can manage a few settings from the &quot;BuddyPress&quot; link under &quot;Site Admin&quot;. To view your new network and profile click &quot;My Account&quot; from the admin bar at the top of the screen and select &quot;Activity&quot; or &quot;Profile&quot;.</p>
<h3>Step 7 &#8211; Additonal Plugins and Themes</h3>
<p>The plugin space for BuddyPress is small right now, but it will probably  explode with new activity like WordPress once did. However, there are a few cool <a href="http://buddypress.org/extend/plugins/">plugins</a> available for BuddyPress right now:</p>
<ul>
<li><a href="http://wordpress.org/extend/plugins/bpgroups">bpGroups</a> which includes improvements to the group system.</li>
<li><a href="http://wordpress.org/extend/plugins/invitefriends-plug-in">Invite Friends</a> which adds some functionality to allow you to add friends from other social networking applications like Twitter, Facebook and GMail.</li>
<li><a href="http://wordpress.org/extend/plugins/twittertowire">Twitter To Wire</a> which adds your tweets to your wire (the BuddyPress version of Facebook&#39;s Wall) automatically.</li>
</ul>
<p>There is also a <a>page for themes</a>, but no themes have yet been made available for download. If you are curious about  the power of the theming system, you can view a few examples at  <a href="http://wannanetwork.com/">WannaNetwork</a>, <a href="http://grungepress.com/">GrungePress</a>, and <a href="http://flokka.com/">Flokka</a>.</p>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/263_buddypress/buddypress/extend.png" alt="Extend Screen Shot" style="width: 287px;" />
</div>
<h3>Closing</h3>
<p>I hope this tutorial has been successful in introducing you to BuddyPress and has opened up an opportunity for you to start your own social network site. The Wordpress MU / BuddyPress configuration provides more social functionality than can be provided by a simple forum or blog network setup.</p>
<p>Remember,  this  tutorial is meant to familiarize you with the software and its installation before its final release. If you want to continue with your BuddyPress installation on the programming side of things, the BuddyPress Codex has some <a href="http://codex.buddypress.org/developer-docs/">developer documentation</a>.</p>
</p>
<ul class="webroundup">
<li>Subscribe to the <a href="http://feeds.feedburner.com/nettuts" title="NETTUTS RSS Feed">NETTUTS RSS Feed</a> for more daily web development tuts and articles.</li>
</ul>
<p>
<script type="text/javascript"><!--digg_url = "post permalink (not digg url)"; // -->
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/social-networking-with-buddypress/feed/</wfw:commentRss>
		<slash:comments>86</slash:comments>
		</item>
		<item>
		<title>Create a Custom WordPress Plugin From Scratch</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 17:52:54 +0000</pubDate>
		<dc:creator>Cristian Lupu</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://nettuts.com/?p=2668</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/wplugin.png" alt="Build a Custom WordPress Plugin" />]]></description>
			<content:encoded><![CDATA[<p>This tutorial will describe the implementation of a Wordpress plugin starting from scratch. The plugin will connect to an external OSCommerce database and display random products on your Wordpress site. It also implements a configuration page for the Wordpress admin panel.</p>
<p><span id="more-2668"></span></p>
<div class="tutorial_image">
<a href="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/Plugin files.zip"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt=""></a>
</div>
<h3>Introduction</h3>
<p>Wordpress is gaining more and more popularity each day, not just as a blogging platform but also as a basic CMS, thus improving and extending its basic functionality becoming a day-to-day necessity for a lot of developers. Fortunately, the Wordpress developers have foreseen these needs and added the possibility of customizing the basic functionality by adding plugins. Basicaly, a Wordpress plugin is a (more or less) stand-alone piece of code that can be executed in different sections and stages within a page or site.</p>
<p>In today&#8217;s tutorial we&#8217;ll be talking about creating a Wordpress plugin that extracts and displays products from an external OSCommerce shop database. We will start by describing the file structure of a plugin and where it must be included in the Wordpress structure, then we&#8217;ll be having a closer look at how to make our plugin visible for Wordpress and integrating it with actions run by its frame. Next, we&#8217;ll be creating a configuration panel for our plugin to allow the site administrator to customize it to his/her needs. Once done, we&#8217;ll be implementing the front-end functions themselves that will interact with the OSCommerce database and extract the required data. Finally, we&#8217;ll be modifying the default template to display the extracted data in the sidebar. Excited? Let&#8217;s get started!</p>
<div class="tutorial_image">
<img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/20090120-114215.png" alt="Final Product" />
</div>
<h3>Getting started</h3>
<p>While it would be possible to follow this tutorial by simply reading through it, I would recommend installing Wordpress on your computer and follow the tutorial implementing all the steps. For this, you&#8217;ll need a local server running on your machine, like <a href="http://www.apachefriends.org/en/xampp.html" target="_blank">XAMPP</a> for instance. Once you have it running, <a href="http://wordpress.org/download/" target="_blank">download</a> and install Wordpress. You will find extensive information about the <a href="http://codex.wordpress.org/Getting_Started_with_WordPress#Installation" target="_blank">installation process and troubleshooting</a> on the Wordpress site. For this tutorial we will be using release 2.7</p>
<p>Further on, you will need to set up an OSCommerce shop on your machine. You can download the latest release here: <a href="http://www.oscommerce.com/solutions/downloads" target="_blank">http://www.oscommerce.com/solutions/downloads</a></p>
<h3>Files and folders</h3>
<p>First, we&#8217;ll need to create our basic files and folder structure. Wordpress stores its plugins in the <em>wp-content/plugins/</em> folder. This is the place where we&#8217;ll be adding our files as well. Normally, if your plugin is going to be very simple, you will include all the code inside one single PHP file. In this case, you will simply store the file in the folder mentioned above. However, in our case, we are going to use two files (one for the main plugin file and one for implementing the administration page) therefore we&#8217;ll be putting all our files in a specific folder that we&#8217;ll name <em>oscommerce_importer</em>. Go ahead and create this folder.</p>
<h3>Creating the plugin file</h3>
<p>Next, we must create our main plugin file. We&#8217;ll name it <em>oscommerce_importer.php</em>. You can really name it whatever you want, it doesn&#8217;t make any difference.</p>
<p>If you now open your Wordpress administration panel and navigate to the <em>Plugins</em> sections, your screen will look something like this:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/images/admin_no_plugin.jpg" alt="Admin panel" title="Admin panel" width="550" height="344" /></div>
<p>As you can see, there is not the slightest sign of our new plugin. It&#8217;s time to change that and tell Wordpress that our file is going to implement a plugin. The process to do so is very simple. All we need to do is add a plugin specific information header to our newly created file. This standard header will look like this:</p>
<pre name="code" class="php">
	&lt;?php
		/*
		Plugin Name: OSCommerce Product Display
		Plugin URI: http://www.orangecreative.net
		Description: Plugin for displaying products from an OSCommerce shopping cart database
		Author: C. Lupu
		Version: 1.0
		Author URI: http://www.orangecreative.net
		*/
	?&gt;
	</pre>
<p>Simple enough, don&#8217;t you think? You can, of course, change the content of this header to your liking but make sure you keep all the lines, otherwise Wordpress won&#8217;t correctly recognize your plugin.</p>
<p>If you refresh your administration panel&#8217;s plugin page, you&#8217;ll now see our plugin listed along with the other ones.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/images/admin_with_deactivated_plugin.jpg" alt="Admin panel with deactivated plugin" title="Admin panel with deactivated plugin" width="550" height="361" /></div>
<p>See how all the relevant information like name, description, author, URL are extracted from the information header? This is why it is always important to correctly fill out this information. Let&#8217;s go and activate our plugin by clicking <em>Activate</em> to the right of the plugin entry.</p>
<h3>Working with action hooks</h3>
<p>Our plugin is now shown in the administration panel so Wordpress is aware of it. However, it doesn&#8217;t do anything as it contains nothing except of the information header. We are going to change this now.</p>
<p>Wordpress offers a great way to include your plugin code in different places all over the template, be it physical positions within a page or logical positions within the process of building up a page that is going to be displayed. First, we are going to have a closer look at the second category, the logical positions, better known as action hooks.</p>
<h4>Action Hooks </h4>
<p>You can view action hooks as callback function. Whenever Wordpress is executing a certain operation, like, for instance, displaying the page footer, it will allow your plugins to execute their own code that must be run at that exact moment.</p>
<p>For a better understanding, let&#8217;s consider a generic plugin called <em>my_plugin</em> that implements a function called <em>mp_footer()</em> that has to be run whenever the page footer is displayed. We will tell Wordpress to call this function, at the moment of displaying the footer by using a special function called <em>add_action()</em>:</p>
<pre name="code" class="php">
		&lt;php add_action('wp_footer', 'mp_footer'); ?&gt;
	</pre>
<p>The <em>add_action()</em> function takes the action hook name as its first parameter and the name of the function that must be executed, as a second parameter. This function call will be added to your main plugin file (the one containing the information header), usually, right under the function code that needs to be executed (<em>mp_footer()</em> in our example). You will find the <a href="http://codex.wordpress.org/Plugin_API/Action_Reference" target="_blank">full list of available action hooks</a> in the Wordpress Codex.</p>
<p>We&#8217;ll be using action hooks in the next chapter, where we are going to build the administration page for our plugin.</p>
<h3>Creating the plugin&#8217;s administration page</h3>
<p>We&#8217;ll start the implementation of the module by defining its configurable parameters and make these accessible to the site administrator. Let&#8217;s see what these configuration bits would be:</p>
<ul>
<li>Database settings</li>
<ul>
<li>database host</li>
<li>database name</li>
<li>database user</li>
<li>database password</li>
</ul>
<li>Store settings</li>
<ul>
<li>store URL</li>
<li>folder for the product images</li>
</ul>
</ul>
<p>First, we need the database host, name, user and password in order to be able to connect to it and extract the needed data. Second, we need some general data about the store like its URL and the folder where the product images are stored. We need this information in order to be able to build the links because the paths contained in the database are all relative the previously mentioned product image folder.</p>
<p>Now that we know what we want to include in the configuration panel, it&#8217;s time to implement it. We&#8217;ll start by creating a new menu item to access the page and we&#8217;ll place it inside the <em>Settings</em> menu. Remember our chat about the action hooks in the previous chapter? It&#8217;s time to use this feature.</p>
<p>If you&#8217;ll scroll over the <a href="http://codex.wordpress.org/Plugin_API/Action_Reference" target="_blank">list of action hooks</a>, you&#8217;ll see that Wordpress also provides one that gets called when the basic menu structure has been generated (<em>admin_menu</em>) so, this would be the optimal place to chime in and create our own menu item.</p>
<p>Now that we identified the action we are going to use, all we need is to define our own function that will be called when this action hook runs. We&#8217;ll call our function <em>oscimp_admin_actions()</em> where <em>oscimp_</em> stands for <em><strong>osc</strong>ommerce <strong>imp</strong>orter</em> and is used to create a possibly unique function name that will not get mismatched with any other function within Wordpress or any of its plugins. Let&#8217;s see how the code will look like:</p>
<pre name="code" class="php">
		function oscimp_admin_actions() {

		}

		add_action('admin_menu', 'oscimp_admin_actions');
	</pre>
<p>As you can see, we are creating our function <em>oscimp_admin_actions()</em> then associate it with the <em>admin_menu</em> action hook using the <em>add_action()</em> function. The next step would then be to add some code to our <em>oscimp_admin_actions()</em> function to actually create the new menu item.</p>
<p>As with most Wordpress things, adding a new menu item is also very easy. It all boils down to calling a single function. We would like to add our new menu item to the <em>Settings</em> menu so, in this case the function we need is <em>add_options_page()</em>. We&#8217;ll add the code inside the <em>oscimp_admin_actions()</em> function.</p>
<pre name="code" class="php">
		function oscimp_admin_actions() {
			add_options_page("OSCommerce Product Display", "OSCommerce Product Display", 1, "OSCommerce Product Display", "oscimp_admin");
		}

		add_action('admin_menu', 'oscimp_admin_actions');
	</pre>
<p>If you refresh your admin page, you&#8217;ll see the new menu item appear under <em>Settings</em>.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/images/admin_new_menu_item.jpg" alt="New menu item" title="New menu item" width="160" height="262" /></div>
<p>Each existing menu has its own function to be used to add sub-menu items. For instance, if we would like to add our sub-menu item to the <em>Tools</em> menu instead of <em>Settings</em>, we would use the <em>add_management_page()</em> function instead of <em>add_options_page()</em>. You can find more details about the available options in the <a href="http://codex.wordpress.org/Adding_Administration_Menus" target="_blank">Adding Administration Menus</a> section of the Wordpress Codex.</p>
<p>If we get back to the newly added code line, you&#8217;ll probably notice the last parameter. This is actually a function name that will be called when the newly added menu item is clicked on and will be used to build the administration page of our plugin. Next, we&#8217;ll be adding this new function. However, before proceeding we should stop for a moment and think about what will be implemented on this page.</p>
<p>We already defined the parameters we want to make configurable (database host, name, user, etc) so these will have to be included in a form in order to allow the user to send the data to the database. Once the form is defined, we&#8217;ll need a bit of code that extracts the sent data from the form and saves it to the database. Last but not least, we need some code to extract the existing data from the database (if any) and pre-populate the form with these values. As you can see, there are quite a few things to do so, it might be a good idea to separate this functionality to its own file. We&#8217;ll name the file <em>oscommerce_import_admin.php</em>. Now, go and create an empty file with the given name.</p>
<p>As already mentioned, we&#8217;ll have to create the function that will display our plugin configuration page (we named this function <em>oscimp_admin()</em>). The code inside this function will be included from our newly created PHP file, <em>oscommerce_import_admin.php</em></p>
<pre name="code" class="php">
		function oscimp_admin() {
			include('oscommerce_import_admin.php');
		}

		function oscimp_admin_actions() {
			add_options_page("OSCommerce Product Display", "OSCommerce Product Display", 1, "OSCommerce Product Display", "oscimp_admin");
		}

		add_action('admin_menu', 'oscimp_admin_actions');
	</pre>
<p>If you now click on the link under the <em>Settings</em> menu, you will be directed to an empty page. This is because our <em>oscommerce_import_admin.php</em>file is still empty.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/images/admin_empty_config_page.jpg" alt="Empty plugin configuration page" title="Empty plugin configuration page" width="550" height="400" /></div>
<p>Next, we are going to create our form. For this we&#8217;ll use the following code:</p>
<pre name="code" class="html">
		&lt;div class="wrap"&gt;
			&lt;?php    echo "&lt;h2&gt;" . __( 'OSCommerce Product Display Options', 'oscimp_trdom' ) . "&lt;/h2&gt;"; ?&gt;

			&lt;form name="oscimp_form" method="post" action="&lt;?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?&gt;"&gt;
				&lt;input type="hidden" name="oscimp_hidden" value="Y"&gt;
				&lt;?php    echo "&lt;h4&gt;" . __( 'OSCommerce Database Settings', 'oscimp_trdom' ) . "&lt;/h4&gt;"; ?&gt;
				&lt;p&gt;&lt;?php _e("Database host: " ); ?&gt;&lt;input type="text" name="oscimp_dbhost" value="&lt;?php echo $dbhost; ?&gt;" size="20"&gt;&lt;?php _e(" ex: localhost" ); ?&gt;&lt;/p&gt;
				&lt;p&gt;&lt;?php _e("Database name: " ); ?&gt;&lt;input type="text" name="oscimp_dbname" value="&lt;?php echo $dbname; ?&gt;" size="20"&gt;&lt;?php _e(" ex: oscommerce_shop" ); ?&gt;&lt;/p&gt;
				&lt;p&gt;&lt;?php _e("Database user: " ); ?&gt;&lt;input type="text" name="oscimp_dbuser" value="&lt;?php echo $dbuser; ?&gt;" size="20"&gt;&lt;?php _e(" ex: root" ); ?&gt;&lt;/p&gt;
				&lt;p&gt;&lt;?php _e("Database password: " ); ?&gt;&lt;input type="text" name="oscimp_dbpwd" value="&lt;?php echo $dbpwd; ?&gt;" size="20"&gt;&lt;?php _e(" ex: secretpassword" ); ?&gt;&lt;/p&gt;
				&lt;hr /&gt;
				&lt;?php    echo "&lt;h4&gt;" . __( 'OSCommerce Store Settings', 'oscimp_trdom' ) . "&lt;/h4&gt;"; ?&gt;
				&lt;p&gt;&lt;?php _e("Store URL: " ); ?&gt;&lt;input type="text" name="oscimp_store_url" value="&lt;?php echo $store_url; ?&gt;" size="20"&gt;&lt;?php _e(" ex: http://www.yourstore.com/" ); ?&gt;&lt;/p&gt;
				&lt;p&gt;&lt;?php _e("Product image folder: " ); ?&gt;&lt;input type="text" name="oscimp_prod_img_folder" value="&lt;?php echo $prod_img_folder; ?&gt;" size="20"&gt;&lt;?php _e(" ex: http://www.yourstore.com/images/" ); ?&gt;&lt;/p&gt;

				&lt;p class="submit"&gt;
				&lt;input type="submit" name="Submit" value="&lt;?php _e('Update Options', 'oscimp_trdom' ) ?&gt;" /&gt;
				&lt;/p&gt;
			&lt;/form&gt;
		&lt;/div&gt;
	</pre>
<h4>Explaining the Code </h4>
<p>If you are familiar with HTML and PHP, the code above will make some sense but, still, let us shortly walk through the lines. </p>
<ul>
<li>We start by creating a <em>div</em> with the class <em>wrap</em>. This is a standard Wordpress class that will make our page look like any other page in the administration area. </li>
<li>The form will be using the POST method to send data back to itself. This means that the form data will be received by the same page so, we can add the database update code to the same file.</li>
<li>Next, there is a hidden field that will be used to determine whether the current page is displayed after the user has pressed the <em>Update Options</em> button or not. When the page receives the form data, the value of this field will be set to <em>Y</em>.</li>
<li>The next lines will create the form input fields for the database and store settings. As you can easily see, the <em>value</em> parameters are be set by the content of PHP variables. We&#8217;ll talk about these soon.</li>
<li>Now if you refresh the admin page, you&#8217;ll see our newly created form. However, pressing the <em>Update Options</em> button will have no effect other than refreshing the page and the form fields are empty.</li>
</ul>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/images/admin_config_page_with_form.jpg" alt="Plugin configuration page with form" title="Plugin configuration page with form" width="550" height="400" /></div>
<h4>Handling the Data</h4>
<p>Once the form is ready to go, we&#8217;ll take care of the form data handling itself, updating the database and retrieving existing option values from the database. For this, we&#8217;ll first have to decide whether the current page is displayed after the user has pressed the <em>Update Options</em> button or not. We&#8217;ll do this by analyzing the value of the form&#8217;s hidden field, <em>oscimp_hidden</em>. The following code will be added at the very beginning of our <em>oscommerce_import_admin.php</em> file, before the code for displaying the form:</p>
<pre name="code" class="php">
	&lt;?php
		if($_POST['oscimp_hidden'] == 'Y') {
			//Form data sent
		} else {
			//Normal page display
		}
	?&gt;
	</pre>
<p>Next, we&#8217;ll be handling the form data and update the plugin options in the database accordingly. For this we&#8217;ll be using the <em>update_option()</em> function. The first parameter of this function is the option name which will be sued later to uniquely identify this option and its value. The second parameter is the value to be assigned.</p>
<pre name="code" class="php">
	&lt;?php
		if($_POST['oscimp_hidden'] == 'Y') {
			//Form data sent
			$dbhost = $_POST['oscimp_dbhost'];
			update_option('oscimp_dbhost', $dbhost);

			$dbname = $_POST['oscimp_dbname'];
			update_option('oscimp_dbname', $dbname);

			$dbuser = $_POST['oscimp_dbuser'];
			update_option('oscimp_dbuser', $dbuser);

			$dbpwd = $_POST['oscimp_dbpwd'];
			update_option('oscimp_dbpwd', $dbpwd);

			$prod_img_folder = $_POST['oscimp_prod_img_folder'];
			update_option('oscimp_prod_img_folder', $prod_img_folder);

			$store_url = $_POST['oscimp_store_url'];
			update_option('oscimp_store_url', $store_url);
			?&gt;
			&lt;div class="updated"&gt;&lt;p&gt;&lt;strong&gt;&lt;?php _e('Options saved.' ); ?&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;
			&lt;?php
		} else {
			//Normal page display
		}
	?&gt;
	</pre>
<p>The code above if pretty much self-explanatory but please note that here we are using the PHP variables we have previously mentioned while building the form. These variables will be updated with the current form data values and will be displayed in the form itself. Go, check it out! Refresh the configuration page and enter your OSCommerce database settings as well as your store parameters then press <em>Update Options</em>.</p>
<p>If everything was implemented like described above, you&#8217;ll see an <em>Options saved</em> success message and the form fields will contain the data you have just entered.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/images/admin_form_send_success.jpg" alt="Plugin configuration page with success message" title="Plugin configuration page with success message" width="550" height="400" /></div>
<p>Last but not least, we&#8217;ll need to pre-populate the form with the database data when the user opens the configuration page. For this, we&#8217;ll be using the <em>get_option()</em> function which retrieves the specified option from the database.</p>
<pre name="code" class="php">
	&lt;?php
		if($_POST['oscimp_hidden'] == 'Y') {
			//Form data sent
			$dbhost = $_POST['oscimp_dbhost'];
			update_option('oscimp_dbhost', $dbhost);

			$dbname = $_POST['oscimp_dbname'];
			update_option('oscimp_dbname', $dbname);

			$dbuser = $_POST['oscimp_dbuser'];
			update_option('oscimp_dbuser', $dbuser);

			$dbpwd = $_POST['oscimp_dbpwd'];
			update_option('oscimp_dbpwd', $dbpwd);

			$prod_img_folder = $_POST['oscimp_prod_img_folder'];
			update_option('oscimp_prod_img_folder', $prod_img_folder);

			$store_url = $_POST['oscimp_store_url'];
			update_option('oscimp_store_url', $store_url);
			?&gt;
			&lt;div class="updated"&gt;&lt;p&gt;&lt;strong&gt;&lt;?php _e('Options saved.' ); ?&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;
			&lt;?php
		} else {
			//Normal page display
			$dbhost = get_option('oscimp_dbhost');
			$dbname = get_option('oscimp_dbname');
			$dbuser = get_option('oscimp_dbuser');
			$dbpwd = get_option('oscimp_dbpwd');
			$prod_img_folder = get_option('oscimp_prod_img_folder');
			$store_url = get_option('oscimp_store_url');
		}
	?&gt;
	</pre>
<p>You can test the code above by simply navigating to another page within the admin area and then retuning to this page by clicking the <em>OSCommerce Product Display</em> sub-menu item in the <em>Setting</em> menu. If everything goes well, you will see the form with all the fields pre-populated with the data you have entered.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/images/admin_with_populated_form.jpg" alt="Plugin configuration page with pre-populated form" title="Plugin configuration page with pre-populated form" width="550" height="400" /></div>
<p>With this last piece of code, we have finished implementing the plugin&#8217;s configuration page so, let&#8217;s review what has been done in this chapter:</p>
<ul>
<li>we defined what parameters need to be configured by the site administrator</li>
<li>we added an action hook for when the menu is displayed in the administration panel to help us add a new sub-menu item for our plugin</li>
<li>we have added a new sub-menu item to the <em>Settings</em> menu that will link to our plugin&#8217;s configuration page</li>
<li>we have defined a function that will build the plugin&#8217;s configuration page and separated its code in a second PHP file</li>
<li>we have built the form containing the user inputs for each of the configurable data bits</li>
<li>we have built the database update function</li>
<li>we have built a function that will pre-populate the form with the option values stored in the database</li>
</ul>
<h3>Creating the user function</h3>
<p>Well, everything went quite fine so far but our plugin is yet unusable because we haven&#8217;t implemented the part that will actually allow us to display the products in the front-end.</p>
<p>In order to allow our users to display the products in the front-end, we&#8217;ll need to declare a function that can be called from the template&#8217;s PHP code and which will return the HTML code to be inserted in the template. We are going to name this function <em>oscimp_getproducts()</em> and accept the number of products to be displayed as a function parameter. The function itself will be implemented in our plugin&#8217;s main file, <em>oscommerce_import.php</em></p>
<pre name="code" class="php">
		function oscimp_getproducts($product_cnt=1) {

		}
	</pre>
<p>As you can see, we are assigning a default value to our function parameter thus allowing our users to call the function both with and without a parameter. If the function is called with a parameter, like <em>oscimp_getproducts(3)</em>, it will display three products. If the function is called without a parameter, like <em>oscimp_getproducts()</em>, it will only display one product.</p>
<p>First thing in our function would be to establish a connection to the OSCommerce database. Thanks to our plugin configuration page, we now have all the information we need: database host, name, user and password. We&#8217;ll be using the built-in <em>wpdb</em> class to create a new database object.</p>
<pre name="code" class="php">
		function oscimp_getproducts($product_cnt=1) {
			//Connect to the OSCommerce database
			$oscommercedb = new wpdb(get_option('oscimp_dbuser'),get_option('oscimp_dbpwd'), get_option('oscimp_dbname'), get_option('oscimp_dbhost'));
		}
	</pre>
<p>Once this is done, we declare a variable that will contain the HTML code and start quering the OSCommerce database for each of the specified number of products. The code below merely implements this query loop and can be further-on improved by checking for duplicates, for instance, but this is not the subject of this tutorial so, we&#8217;ll keep it simple for the sake of readability.</p>
<pre name="code" class="php">
		function oscimp_getproducts($product_cnt=1) {
			//Connect to the OSCommerce database
			$oscommercedb = new wpdb(get_option('oscimp_dbuser'),get_option('oscimp_dbpwd'), get_option('oscimp_dbname'), get_option('oscimp_dbhost'));

			$retval = '';
			for ($i=0; $i&lt;$product_cnt; $i++) {
				//Get a random product
				$product_count = 0;
				while ($product_count == 0) {
					$product_id = rand(0,30);
					$product_count = $oscommercedb-&gt;get_var("SELECT COUNT(*) FROM products WHERE products_id=$product_id AND products_status=1");
				}

				//Get product image, name and URL
				$product_image = $oscommercedb-&gt;get_var("SELECT products_image FROM products WHERE products_id=$product_id");
				$product_name = $oscommercedb-&gt;get_var("SELECT products_name FROM products_description WHERE products_id=$product_id");
				$store_url = get_option('oscimp_store_url');
				$image_folder = get_option('oscimp_prod_img_folder');

				//Build the HTML code
				$retval .= '&lt;div class="oscimp_product"&gt;';
				$retval .= '&lt;a href="'. $store_url . 'product_info.php?products_id=' . $product_id . '"&gt;&lt;img src="' . $image_folder . $product_image . '" /&gt;&lt;/a&gt;&lt;br /&gt;';
				$retval .= '&lt;a href="'. $store_url . 'product_info.php?products_id=' . $product_id . '"&gt;' . $product_name . '&lt;/a&gt;';
				$retval .= '&lt;/div&gt;';

			}
			return $retval;
		}
	</pre>
<p>Once this is done, all we have to do is insert the <em>oscimp_getproducts()</em> function call to the template. We&#8217;ll be displaying three products at the bottom of the sidebar so, we are going to modify the <em>sidebar.php</em> file of our template, inserting the following code right below the list item containing the meta links:</p>
<pre name="code" class="php">
		&lt;li&gt;&lt;?php echo oscimp_getproducts(3); ?&gt;&lt;/li&gt;
	</pre>
<p>If you refresh your front-end page now, you&#8217;ll see the three random products displayed at the bottom of the sidebar.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/186_wordPressPlugin/images/frontpage_with_products.jpg" alt="Frontpage with random products" title="Frontpage with random products" width="550" height="720" /></div>
<p>With this last piece of code, we have finished implementing the front-end function as well.</p>
<h3>Conclusion</h3>
<p>We have now implemented a Wordpress plugin from scratch. Let&#8217;s summarize what has been done:</p>
<ul>
<li>we defined the way we store our plugin files</li>
<li>we defined the information header in order to make our plugin visible for Wordpress</li>
<li>we talked about the action hooks and the way these are used</li>
<li>we defined what parameters need to be configured by the site administrator</li>
<li>we added an action hook for when the menu is displayed in the administration panel to help us add a new sub-menu item for our plugin</li>
<li>we have added a new sub-menu item to the <em>Settings</em> menu that will link to our plugin&#8217;s configuration page</li>
<li>we have defined a function that will build the plugin&#8217;s configuration page and separated its code in a second PHP file</li>
<li>we have built the form containing the user inputs for each of the configurable data bits</li>
<li>we have built the database update function</li>
<li>we have built a function that will pre-populate the form with the option values stored in the database</li>
<li>we have built our user function for use in the template</li>
<li>we connected to the OSCommerce database</li>
<li>we queried the OSCommerce database extracting the product ID, image and name</li>
<li>we have built the HTML code for displaying the extracted data</li>
<li>we have included the user function to the template sidebar</li>
</ul>
<p>I hope this tutorial gave you all the information you need to build a Wordpress plugin from the beginning. Please feel free to post your comments below.</p>
<p>Thanks for reading! <img src='http://net.tutsplus.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<ul class="webroundup">
<li>Subscribe to the <a href="http://feeds.feedburner.com/nettuts" title="NETTUTS RSS Feed">NETTUTS RSS Feed</a> for more daily web development tuts and articles.</li>
</ul>
<p>
<script type="text/javascript"><!--digg_url = "post permalink (not digg url)"; // -->
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/feed/</wfw:commentRss>
		<slash:comments>148</slash:comments>
		</item>
		<item>
		<title>Anatomy of a WordPress Plugin</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/anatomy-of-a-wordpress-plugin/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/anatomy-of-a-wordpress-plugin/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 10:30:57 +0000</pubDate>
		<dc:creator>Jarkko Laine</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://nettuts.com/?p=2127</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/151_wpPlugin/200x200.png" alt="Anatomy of a WordPress Plugin" />]]></description>
			<content:encoded><![CDATA[<p>
	WordPress is well known for its amazing collection of free plugins. There is one for almost every need<br />
	you can think of, from backing up your WordPress installation to asking for a cup of coffee<br />
	or fighting spam.
</p>
<p>
	But there are times when none of the available plugins seem to quite do the trick you are looking for. To help you in moments like<br />
	that, this tutorial will guide you through every step of building a simple, widgetized WordPress plugin with settings.
</p>
<p><span id="more-2127"></span></p>
<div class="tutorial_image">
<a href="http://nettuts.s3.amazonaws.com/151_wpPlugin/coming-next.zip"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt=""></a>
</div>
<p>
	Writing your own plugin is not rocket science reserved for the most savvy programmers. All you need<br />
	is <a href="http://nettuts.com/tutorials/php/learn-php-from-scratch-a-training-regimen/">a basic understanding of<br />
	the PHP programming language</a> and some information on how WordPress expects your plugin to behave. This tutorial will provide you with the latter.
</p>
<h3>The Goal</h3>
<p>
	Before we get started, let me introduce the concept of the plugin and what we are trying to achieve with it.
</p>
<p>
	&#8220;Coming Next&#8221; will be a widget plugin that queries a given number of blog posts scheduled for the future and lists them in the blog&#8217;s sidebar (or where ever<br />
	the blog owner decides to place the widget). The widget will be customizable so that the user can decide how many posts he wants to list,<br />
	if a summary of the post should be shown, and what the date format should be. The looks of the widget should be easily customizable through CSS.
</p>
<p>
	Here is a quick drawing of how the widget could look like in action:
</p>
<div class="tutorial_image">
	<img src="http://nettuts.s3.amazonaws.com/151_wpPlugin/plugin1-7.jpg"/><br/>
</div>
<p>
	Let&#8217;s get started!
</p>
<h3>Step 1: The Plugin Template</h3>
<p>
	Plugins in WordPress are PHP files that have been put in the <strong><code>wp-content/plugins</code></strong> directory under the WordPress installation directory.
</p>
<p>
	For simple plugins that fit nicely in just one file, like the one we are creating today, it&#8217;s enough to create a single PHP file and upload it to the<br />
	plugin directory. It is, however, a good practice to always create a separate directory for every plugin and that way help the blog owners keep their plugins<br />
	organized. This will also make it easier to expand your plugin if you ever need to add new files to it.
</p>
<p>
	Let&#8217;s create a directory for the &#8220;Coming Next&#8221; plugin:
</p>
<div class="tutorial_image">
	<img src="http://nettuts.s3.amazonaws.com/151_wpPlugin/plugin1-0.jpg"/><br/><br />
	Created directory: /wp-content/plugins/coming-next
</div>
<p>
	In this new directory, we then create the plugin&#8217;s main PHP file. Let&#8217;s call it <strong><code>coming-next.php</code></strong>.
</p>
<p>
	When searching for plugins, WordPress goes through each file inside the plugin directory looking for comments that identify the files as plugins. That<br />
	comment section tells basic information about the plugin and at the bare minimum needs to contain the name of the plugin.
</p>
<p>
	Here&#8217;s how the comment block for our &#8220;Coming Next&#8221; plugin will look like:
</p>
<pre name="code" class="php">
&lt;?php
/*
Plugin Name: Coming Next
Plugin URI: http://nettuts.com
Description: Shows the next scheduled posts with brief descriptions.
Version: 1.0
Author: Jarkko Laine
Author URI: http://jarkkolaine.com
*/
?&gt;
</pre>
<p>
	Save the file and go to the plugins page in your WordPress admin area. The plugin, with all the information added in the comment,<br />
	is already visible in the the plugin list:
</p>
<div class="tutorial_image">
	<img src="http://nettuts.s3.amazonaws.com/151_wpPlugin/plugin1-1.jpg"/><br/><br />
	This is how the plugin appears on the plugin list
</div>
<p>
	You can already activate the plugin, but as we haven&#8217;t yet put in any code, nothing will happen. We need some functionality.
</p>
<h3>Step 2: Adding Functionality</h3>
<p>
	In its simplest form, a WordPress plugin is nothing more than one or more functions put inside a plugin file.
</p>
<p>
	All functions created in plugins are visible to both the current theme and other active plugins, so it is possible to </p>
<p>	use the plugin system to extend the platform with new functions and then just call them straight from your theme.
</p>
<p>
	Let&#8217;s do that first and create the function at the core of the &#8220;Coming Next&#8221; plugin, <strong><code>list_upcoming_posts()</code></strong>.
</p>
<p>
	One word of warning is in place before we start: Because all functions added in plugin files will be visible throughout your<br />
	WordPress installation, you need to be very careful when naming them. If there are two functions with the same name<br />
	in two (or more) different plugins, they will conflict, and things just cannot work.
</p>
<p>
	For larger plugins it&#8217;s a good idea to do some object oriented programming and create classes to encapsulate parts<br />
	of the functionality. That will give you more freedom in naming your functions and variables. In smaller plugins like<br />
	this one, you just need to be careful, and try to use descriptive function names that you think no one else is using.
</p>
<pre name="code" class="php">
function list_upcoming_posts($num_posts = 1, $show_excerpt = false,
                             $text_format = "Coming Up on [date]") {
  $posts = get_posts("numberposts=".$num_posts."&#038;order=ASC&#038;post_status=future");

  echo "&lt;ul class=\"upcoming-posts\"&gt;";
  global $post;
  $old_post = $post;

  foreach ($posts as $post) :
    setup_postdata($post);
    $my_date = the_date('', '', '', FALSE);
    $coming_up_text = str_replace("[date]", $my_date, $text_format);
  ?&gt;
    &lt;li class="upcoming-post"&gt;
      &lt;span class="upcoming-post-date"&gt;&lt;?php echo $coming_up_text; ?&gt;&lt;/span&gt;
      &lt;span class="upcoming-post-title"&gt;&lt;?php the_title(); ?&gt;&lt;/span&gt;
      &lt;?php if ($show_excerpt) : ?&gt;
        &lt;span class="upcoming-post-description"&gt;
          &lt;?php the_excerpt_rss(); ?&gt;
        &lt;/span&gt;
      &lt;?php endif; ?&gt;
    &lt;/li&gt;
  &lt;?php
  endforeach;

  $post = $old_post;
  setup_postdata($post);
  echo "&lt;/ul&gt;";
}
</pre>
<p>
	This function uses the <strong><a href="http://codex.wordpress.org/Template_Tags/get_posts">get_posts()</a></strong> WordPress<br />
	function to retrieve as many future posts as specified in the <strong>$num_posts</strong> parameter, or all future posts<br />
	if <strong>$num_posts</strong> is greater than the actual number available.
</p>
<p>
	Then it renders a list including the titles of the posts, their scheduled dates, and the excerpt of the post if <strong>$show_excerpt</strong> is set to true.
</p>
<p>
	Note that we need to use the global <strong>$post</strong> variable to setup the post data (see line 10) for function calls such<br />
	as <strong>the_title()</strong> to work. Now, in case the blog template needs access to the current post after rendering the plugin,<br />
	we need to put back the original post once we are finished (see lines 7, and 26-27). Otherwise, the rest of the content would be rendered using the last<br />
	post that was set up using <strong>setup_postdata()</strong>.
</p>
<p>
	Congratulations! You have just written your first WordPress plugin and can test it by adding this call somewhere in your blog template:
</p>
<pre name="code" class="php">
&lt;?php
if (function_exists("list_upcoming_posts")) {
  list_upcoming_posts();
}
?&gt;
</pre>
<p>
	Create a post titled &#8220;Back to the Future&#8221; and schedule it to appear on your blog on January 1st, 2020. Here&#8217;s what you should see:
</p>
<div class="tutorial_image">
	<img src="http://nettuts.s3.amazonaws.com/151_wpPlugin/plugin1-2.jpg"/><br/><br />
	The Plugin in action. Without any CSS styling yet.
</div>
<h3>Step 3: Making the Widget</h3>
<p>
	For some plugins, just having a function you can call from your theme is more than enough. But for this plugin, I think letting the user<br />
	customize the output through his WordPress admin page will provide a nice final touch. And the WordPress widget system is the perfect way to<br />
	achieve that level of user-friendliness.
</p>
<p>
	In case you aren&#8217;t yet familiar with the concept of <a href="http://codex.wordpress.org/Plugins/WordPress_Widgets">WordPress Widgets</a>,<br />
	here&#8217;s what the WordPress documentation says about them:
</p>
<blockquote><p>
	WordPress Widgets allow the easy addition of design elements, gadgets, content, images, and more to your WordPress sidebar to personalize<br />
	your blog without knowing HTML, PHP, or any code. Many WordPress Plugins now come with a Widget version to allow easy addition to the sidebar.
</p></blockquote>
<p>
	If your theme supports widgets, you can go to the Widgets tab in the Design section of your WordPress admin area and assign widgets to the different<br />
	positions that the theme designer has created for them:
</p>
<div class="tutorial_image">
	<img src="http://nettuts.s3.amazonaws.com/151_wpPlugin/plugin1-3.jpg"/><br/><br />
	The &#8220;Widgets&#8221; settings screen
</div>
<p>
	To make our &#8220;Coming Next&#8221; plugin work as a widget, we first need to create a function for rendering the widget. As we can reuse the<br />
	<strong>list_upcoming_posts()</strong> function we created earlier, this task will be rather straightforward.
</p>
<p>
	Here is the code for the widget in its simplest form:
</p>
<pre name="code" class="php">
function widget_coming_next($args) {
  extract($args, EXTR_SKIP);
  echo $before_widget;
  list_upcoming_posts();
  echo $after_widget;
}
</pre>
<p>
	All the function does is that it extracts the HTML markup that the theme designer has set up to be rendered before (<strong>$before_widget</strong>) and<br />
	after (<strong>$after_widget</strong>) every widget, and then renders it around the list of upcoming posts.
</p>
<p>
	The <strong><a href="http://www.php.net/extract">extract()</a></strong> function is standard PHP.<br />
	It takes the fields from the given array (<strong>$args</strong>) and creates local variables out of them. Another way of<br />
	doing the same would have been to reference the array directly using &#8220;before_widget&#8221; and &#8220;after_widget&#8221; as array indices.
</p>
<p>
	Now, the widget knows how to render itself. But before it can be added to a blog, we still need to tell WordPress to add it to the list<br />
	of widgets on the administration page. This is done by creating an initialization function that registers the sidebar widget and adding<br />
	a <a href="http://codex.wordpress.org/Plugin_API/Action_Reference">plugin hook</a> to call that function after all WordPress<br />
	plugins have been loaded into memory.
</p>
<pre name="code" class="php">
function widget_coming_next_init() {
  wp_register_sidebar_widget(COMING_NEXT_WIDGET_ID,
  	__('Coming Next'), 'widget_coming_next');
}

// Register widget to WordPress
add_action("plugins_loaded", "widget_coming_next_init");
</pre>
<p>
	The initialization function calls <strong><a href="http://codex.wordpress.org/WordPress_Widgets_Api/wp_register_sidebar_widget">wp_register_sidebar_widget()</a></strong><br />
	to register the widget to WordPress. The function needs three parameters: a unique identifier for the widget, a name to be used on the Widgets<br />
	page in the admin area and the name of the function that will render the widget.
</p>
<p>
	To make things easier, if we ever need to change the unique identifier, I have created a constant for it. This way, when we use the same constant everywhere,<br />
	we will only have to update it in one place. Add this constant definition at the beginning of the widget file, right after the comment block that identifies the plugin:
</p>
<pre name="code" class="php">
define(COMING_NEXT_WIDGET_ID, "widget_coming_next");
</pre>
<p>
	Now, when you go to check out the &#8220;Widgets&#8221; page, you&#8217;ll see the new widget there waiting to be added on the blog. And when you add<br />
	the widget to a widget position, you&#8217;ll see the upcoming posts appear right where you put them!
</p>
<div class="tutorial_image">
	<img src="http://nettuts.s3.amazonaws.com/151_wpPlugin/plugin1-4.jpg"/><br/><br />
    The &#8220;Coming Next&#8221; widget has now been added to the widget list.
</div>
<h3>Step 4: Widget Settings</h3>
<p>
	Finally, to complete the plugin, we will create a settings menu for updating the widget preferences. The settings box will contain all the same<br />
	parameters that the <strong>list_upcoming_posts()</strong> function takes as paramters. As that function has already been done and<br />
	it knows how to handle the parameters, all that is left is building the settings menu and making it save and retrieve the settings.
</p>
<p>
	Just like for the widget rendering, we will create a function that renders the settings menu and stores the settings<br />
	in the persistent storage, and then tell WordPress about the function so that it knows to show it when adding or editing the widget.
</p>
<p>
	Here&#8217;s the code for storing and retriving the settings:
</p>
<pre name="code" class="php">
function widget_coming_next_control() {
  $options = get_option(COMING_NEXT_WIDGET_ID);
  if (!is_array($options)) {
    $options = array();
  }

  $widget_data = $_POST[COMING_NEXT_WIDGET_ID];
  if ($widget_data['submit']) {
    $options['num_posts'] = $widget_data['num_posts'];
    $options['coming_up_text'] = $widget_data['coming_up_text'];
    $options['show_excerpt'] = $widget_data['show_excerpt'];

    update_option(COMING_NEXT_WIDGET_ID, $options);
  }

  // Render form
  $num_posts = $options['num_posts'];
  $coming_up_text = $options['coming_up_text'];
  $show_excerpt = $options['show_excerpt'];

  // The HTML form will go here
}
</pre>
<p>
	The heart of this function are these two calls to the WordPress API:<br />
	<strong><a href="http://codex.wordpress.org/Function_Reference/get_option">get_option()</a></strong> on line 2 and<br />
	<strong><a href="http://codex.wordpress.org/Function_Reference/update_option">update_option()</a></strong> on line 13.<br />
	<strong>update_option()</strong> can be used to save any variable to the WordPress database as a key-value pair and <strong>get_option</strong> to<br />
	read it.
</p>
<p>
	For example, in the above code snippet, you&#8217;ll see that on line 13, <strong>update_option()</strong> is used to store the <strong>$options</strong> array with the<br />
	key <strong>COMING_NEXT_WIDGET_ID</strong>.
</p>
<p>
	To make things more organized, instead of saving each variable as a separate key-value pair, we put them in an<br />
	array (<strong>$options</strong>) that can be saved at one go.<br />
	This array then holds all the data related to this widget. The array is loaded at the beginning of the function so that the data is available<br />
	for rendering the settings form and the existing settings can be used as form defaults and won&#8217;t get lost when the form gets submitted.
</p>
<p>
	The <strong>widget_coming_next_control()</strong> function gets called both when the settings form is first shown and when the user presses the &#8220;Save Changes&#8221; button<br />
	to store the settings. To identify whether the form has been submitted or not, we use a hidden field<br />
	called <strong>COMING_NEXT_WIDGET_ID[submit]</strong>. If the hidden field has been saved, we read in the parameters from the<br />
	form and save them (lines 8-14). And in both cases, whether data is saved or not, the form is rendered.
</p>
<p>
	Speaking of forms, that core part is still missing. Copy the form below and put it at the end of the function we just created<br />
	(right after line 21, before the closing brace):
</p>
<pre name="code" class="html">
?&gt;


  &lt;label for="&lt;?php echo COMING_NEXT_WIDGET_ID;?&gt;-num-posts"&gt;
    Number of posts to show:
  &lt;/label&gt;
  &lt;input class="widefat"
    type="text"
    name="&lt;?php echo COMING_NEXT_WIDGET_ID; ?&gt;[num_posts]"
    id="&lt;?php echo COMING_NEXT_WIDGET_ID; ?&gt;-num-posts"
    value="&lt;?php echo $num_posts; ?&gt;"/&gt;



  <label for="&lt;?php echo COMING_NEXT_WIDGET_ID;?&gt;-coming-up-text">
    "Coming Up Next" text (use the [date] tag to
    display the publish date):
  </label>
  &lt;input class="widefat" type="text"
    name="&lt;?php echo COMING_NEXT_WIDGET_ID; ?&gt;[coming_up_text]"
    id="&lt;?php echo COMING_NEXT_WIDGET_ID; ?&gt;-coming-up-text"
    value="&lt;?php echo $coming_up_text; ?&gt;"/&gt;



  <label for="&lt;?php echo COMING_NEXT_WIDGET_ID;?&gt;-show-excerpt">
    Show excerpt:
  </label>
  &lt;select class="widefat"
    name="&lt;?php echo COMING_NEXT_WIDGET_ID; ?&gt;[show_excerpt]"
    id="&lt;?php echo COMING_NEXT_WIDGET_ID;?&gt;-show-exceprt"&gt;
    &lt;option value="1" &lt;?php echo ($show_excerpt == "1") ? "selected" : ""; ?&gt;&gt;
      Yes
    &lt;/option&gt;
    &lt;option value="0" &lt;?php echo ($show_excerpt == "1") ? "" : "selected"; ?&gt;&gt;
      No
    &lt;/option&gt;
  &lt;/select&gt;


&lt;input type="hidden"
  name="&lt;?php echo COMING_NEXT_WIDGET_ID; ?&gt;[submit]"
  value="1"/&gt;
&lt;?php
</pre>
<p>
	If you look at the form carefully, you will notice that there are no form opening or ending tags. This is because all active widgets are<br />
	put in the same form, rendered by WordPress, and are saved at one press of &#8220;Save Changes.&#8221; This will be useful when you decide to write<br />
	a widget that can be added many times, such as the WordPress text widget (when doing that you will need to be aware of multiple widgets<br />
	and all their different states at the same time). But for now, it just means that you need to be careful with how you name the fields in your part of the form.
</p>
<p>
	In this plugin, I decided to use the <strong>COMING_NEXT_WIDGET_ID</strong> constant as an identifier to define which of the fields belong to this widget.<br />
	Using the <strong>widget_id[field_id]</strong> notation in the <strong>name</strong> parameters of our <strong>input</strong> tags makes things<br />
	nice for us as they get parsed into an array with <strong>field_id</strong> as the array index.
</p>
<p>
	After creating the settings screen function, we still need to tell WordPress to use it. This is done with the following hook.<br />
	Add it to the <strong>widget_coming_next_init()</strong> function we created earlier:
</p>
<pre name="code" class="html">
  wp_register_widget_control(COMING_NEXT_WIDGET_ID,
      __('Coming Next'), 'widget_coming_next_control');
</pre>
<p>
	Now, when you go to add or edit the widget, you&#8217;ll see that new options have appeared:
</p>
<div class="tutorial_image">
  	<img src="http://nettuts.s3.amazonaws.com/151_wpPlugin/plugin1-5.jpg"/><br/><br />
  	The widget now has settings
</div>
<p>
	Last but not least, we will make the widget rendering use the settings defined in the settings box. It&#8217;s really quite simple: all we need to<br />
	do is to read the settings using the <strong>get_option()</strong> function. Replace the previously created widget rendering function with<br />
	this new version:
</p>
<pre name="code" class="php">
function widget_coming_next($args) {
  extract($args, EXTR_SKIP);
  $options = get_option(COMING_NEXT_WIDGET_ID);

  // Query the next scheduled post
  $num_posts = $options["num_posts"];
  $show_excerpt = $options["show_excerpt"];
  $coming_up_text = $options["coming_up_text"];

  echo $before_widget;
  list_upcoming_posts($num_posts, $show_excerpt, $coming_up_text);
  echo $after_widget;
}
</pre>
<p>
	That&#8217;s it. You have now created a WordPress widget with settings!<br />
	The output still looks rather dull, but with a small touch of CSS, it&#8217;ll come alive and be a perfect match to your blog theme.
</p>
<div class="tutorial_image">
	<img src="http://nettuts.s3.amazonaws.com/151_wpPlugin/plugin1-6.jpg"/><br/><br />
    The Coming Next widget live in action
</div>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/anatomy-of-a-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>99</slash:comments>
		</item>
		<item>
		<title>5 Amazing New WordPress 2.7 Features</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/5-new-wordpress-27-features/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/5-new-wordpress-27-features/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 10:30:59 +0000</pubDate>
		<dc:creator>Harley</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nettuts.com/?p=2077</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/147_wordPress/200x200.png" alt="5 New WordPress 2.7 Features" />]]></description>
			<content:encoded><![CDATA[<p>Wordpress 2.7 is to be publically released in the next week, and a whole bunch of features have been packed in, looking past the obvious such as the new redesign. The new dashboard, Screen options, Plugins, Themes and Core upgrades and the media library!<br />
<span id="more-2077"></span></p>
<h3>New Commenting system</h3>
<p>The Comments section of WordPress has been completely redone, rethought and redesigned. Quick Edit, Reply, and Keyboard Navigation Moderation are the most notable!</p>
<h4>Quick Edit</h4>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/quickedit.png" alt="" /></div>
<p>You are now able to edit comments right from the full comments screen. If you click &#8216;Quick Edit&#8217; when you hover over a comment in the moderation screen, the comment is replaced with an edit panel, where you can edit the Name, URL, email and content of the comment. This inline editor is great as it saves a whole lot of time going to the individual edit screen to edit a comment.</p>
<h4>Reply</h4>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/quickreply.png" alt="" /></div>
<p>So your blog may have heavy discussion, and to reply to them at bulk you have to find the comment, remember what it says, scroll down to the &#8216;add comment&#8217; form, type it and send it off. Now, with WordPress 2.7 you can reply to comments live on the same page. By clicking &#8216;Reply&#8217; a form appears below the comment which you can fill out and reply- quick and easy and painless!</p>
<h4>Keyboard Moderation</h4>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/keyboardMod.png" alt="" /></div>
<p>One of the coolest features yet, WordPress has developed a system with jQuery that allows you to moderate the comments via the keyboard! You can scroll between comments using the <strong>J</strong> and <strong>K</strong> key. <strong>A</strong> approves comments, <strong>U</strong> unapproves the comment, <strong>S</strong> marks the comment as Spam, and <strong>D</strong> deletes the selected comment. <strong>R</strong> initiates the Reply (as above) which you can escape that with <strong>esc</strong>, and <strong>Q</strong> initiates Quick Edit. This allows for a much quicker moderation <em>experience</em>.</p>
<h3>New Dashboard Features</h3>
<p>The messy, clunky <strong>Right Now</strong> section of the old version of WordPress has been pressed into a small grid, which cleanly displays all the information about activity on the website. This enables it to be much more readable and understandable, rather than an ugly spot on the dashboard. It greatly contributes to the refined look of the 2.7 admin.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/rightnow.png" alt="" /></div>
<p>Another cool set of features are the two <strong>QuickPress</strong> and <strong>Press This</strong>.</p>
<p>QuickPress is  basically a very stripped down &#8216;Add Post&#8217; Widget on the front of the Dashboard. It provides, once again a quick way to use frequently accessed functions that usually take pages to get to.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/quickpress.png" alt="" /></div>
<p>Press This is kind of like a Quick Digg Link, or A StumbleUpon quick link. Basically you save a bookmark that looks something like this:</p>
<pre name="code" class="html" style="overflow: auto">&lt;a href="javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://yoursite.com/wp-admin/press-this.php',l=d.location,e=encodeURIComponent,g=f+'?u='+e(l.href)+'&#038;t='+e(d.title)+'&#038;s='+e(s)+'&#038;v=2';function%20a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=720,height=570')){l.href=g;}}a();void(0);"&gt;Press This&lt;/a></pre>
<p>And when you find a website that you like, you can easily blog about it by clicking the Press This Bookmark, which opens a new window with the link to the page you are currently browsing! Great for Networking, and easy enough for anybody to use!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/pressthis.png" alt="" /></div>
<h3>Screen Options</h3>
<p>Due to the monument of information displayed onscreen at any one time, the Developers have added a handy feature called &#8216;Screen Options&#8217;. Basically you can decide which sections you see on any page that has a <img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/screenoptionstab.png" alt="screen options" /> tab. When clicked, it expands to show a number of check buttons that correspond to their sections on the admin page.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/screenoptions.png" alt="" /></div>
<p>These sections are also rearrangeable! You can drag and drop the &#8216;widgets&#8217; around the place, make it so you have your optimum setup possible.</p>
<h3>Plugin Interface</h3>
<p>The guys at WordPress have built in an API for the plugin repository on Wordpress.org/extend, which allows you to install plugins directly from your Admin section. This beats the process of searching, finding, downloading, uploading then activating the plugin, by simply searching, and installing.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/quickinstallplugin.png" alt="" /></div>
<p>It&#8217;s that easy. There is also a Tag Cloud to link to lists of popular search terms/plugins.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/tagcloud.png" alt="" /></div>
<p>For those plugins that are on other sites, there is a simple upload form that allows you to upload the plugin and go from there.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/uploadinstall.png" alt="" /></div>
<h3>Media Library</h3>
<p>Although not significant, this new feature allows you to upload files to your WordPress uploads without having to create a post to do so. This is great if you want to upload a zip or some other large file to your hosting without having to go through FTP. The benefit is that it attaches a whole lot of meta data to the upload too!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/medialibrary.png" alt="" /></div>
<h3>Posts Management</h3>
<p>Post management has been completely revolutionised with &#8216;Bulk Edit&#8217;. By selecting multiple files then adding an &#8216;edit&#8217; filter, you can bulk moderate files in regards to their tags, categories, etc.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/bulkedit.png" alt="" /></div>
<p>If you find a <img src="http://nettuts.s3.amazonaws.com/147_wordPress/postsdisplay.png" alt="post display" /> button, you can also toggle between displaying posts a certain way, with a short excerpt, or without.</p>
<h3>Honourable Mention: Interface change.</h3>
<p>Ok. Understandably I can&#8217;t overlook the biggest new feature; a complete interface overhaul. They have scrapped the colourful motifs, and have moved to a grey colour scheme, that is much more aesthetically pleasing. Word is they also have a blue admin theme in the pipeline!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/147_wordPress/res/newmenu.png" alt="new menu" /></div>
<p>Not only is the menu now vertical (which ensures no wrapping happens, allows for unlimited amounts of menu items, but it is also collapsable. This saves a whole lot of space on the page whilst still having the full menu accessible. Plugin and Theme developers can upload their own icons and use the API to add them to the menu!</p>
<p>The new grey motif is a lot slicker and clean cut that the more childish blue and orange one. The admin interface has always been somewhat unrefined, and WordPress 2.7 finally gives it the overhaul it needs. The new interface is much tighter and robust than the others, whilst still being flexible; a hard feat to achieve! Kudos Jane!</p>
<p>Finally, the new layout is a lot more intelligent, efficient and easier to use. It provides for a more faster and more flexible workflow. It allows you to &#8216;custom build&#8217; your interface so that it suits you best.</p>
<h3>Now what&#8217;s your excuse?</h3>
<p>WordPress 2.7 is the last excuse gone for you not to switch. The new interface and features completely revolutionise blogging, and the tightened interface is a dream to look at. Go get it and learn it!</p>
<ul class="webroundup">
<li>Subscribe to the <a href="http://feeds.feedburner.com/nettuts" title="NETTUTS RSS Feed">NETTUTS RSS Feed</a> for more daily web development tuts and articles.</li>
</ul>
<p>
<script type="text/javascript"><!--digg_url = "post permalink (not digg url)"; // -->
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/5-new-wordpress-27-features/feed/</wfw:commentRss>
		<slash:comments>124</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Ignore Your WordPress Footer</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/dont-ignore-your-wordpress-footer/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/dont-ignore-your-wordpress-footer/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 10:30:38 +0000</pubDate>
		<dc:creator>Harley</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://nettuts.com/?p=1590</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/112_wordPressFooter/200x200.png" alt="WordPress Footer" />]]></description>
			<content:encoded><![CDATA[<p>Footers are often an overlooked aspect of designing a site &#8211; when they can actually be kinda handy and informative. In this tutorial we&#8217;ll go through some options you can have for your WordPress site.</p>
<p><span id="more-1590"></span></p>
<div class="tutorial_image">
<a href="http://nettuts.s3.amazonaws.com/112_wordPressFooter/WPFooter.zip"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt=""></a><br />
<a href="http://nettuts.s3.amazonaws.com/112_wordPressFooter/preview/index.html" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt=""></a></div>
<h3>Preface</h3>
<p>As per usual, with these tutorials, you&#8217;ll need a WordPress directory. By now, if you&#8217;ve been doing them you should already have one setup! If not, there are tutorials on running Wordpress locally <a href="http://geeksaresexy.blogspot.com/2006/06/installing-wordpress-locally-under.html" title="geeks are sexy on how to install wordpress locally under XP">here for Windows</a>, and <a href="http://michaeldoig.net/4/installing-mamp-and-wordpress.htm" title="Michael Doig on installing wordpress locally under OS X">here for OS X</a>.</p>
<p>We&#8217;ll be going through how to create a static footer with all the information you need, then we&#8217;ll make it dynamic so you can edit it all via WordPress Backend!</p>
<p><a href="http://nettuts.s3.amazonaws.com/112_wordPressFooter/res/images.zip"><strong>Download</strong> these images</a>, and place them in a new folder in the wp-content/themes. Name the folder &#8216;WPFooter&#8217;.</p>
<h3>Step 1 &#8211; The WordPress code</h3>
<p>Quickly, place this code in a new file &#8217;style.css&#8217; within the new WPFooter folder:</p>
<pre name="code" class="css">/*
Theme Name: WPFooter
Theme URI: http://nettuts.com/
Description: A handy WordPress footer.
Version: 1.0
Author: Harley Alexander
Author URI: http://www.baffleinc.com/
*/</pre>
<p>If you open up your WordPress directory in a browser, navigate to wp-admin/themes.php, and select the new theme!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/112_wordPressFooter/res/activatetheme.png" alt="" /></div>
<p>&#8221;</p>
<p>We&#8217;ll only show a short header and a simple loop for this. Later on in the tutorial, we&#8217;ll go through having multiple Sidebars (one for the sidebar, one for the footer). We&#8217;ll start off with an easy base:</p>
<pre name="code" class="php">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head profile="http://gmpg.org/xfn/11"&gt;

	&lt;title&gt;&lt;?php bloginfo('name'); ?&gt;&lt;?php wp_title(); ?&gt;&lt;/title&gt;

	&lt;link rel="stylesheet" href="&lt;?php bloginfo('stylesheet_url'); ?&gt;" type="text/css" media="screen" /&gt;
	&lt;link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="&lt;?php bloginfo('rss2_url'); ?&gt;" /&gt;
	&lt;?php wp_head(); ?&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;h1&gt;&lt;a href="&lt;?php bloginfo('url'); ?&gt;"&gt;&lt;?php bloginfo('name'); ?&gt;&lt;/a&gt;&lt;/h1&gt;
	&lt;div id="wrapper"&gt;
		&lt;div id="content"&gt;
			&lt;?php if(have_posts()) : while(have_posts()) : the_post(); ?&gt;
				&lt;div class="entry"&gt;
					&lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
					&lt;?php the_content(); ?&gt;
				&lt;/div&gt;
			&lt;?php endwhile; endif; ?&gt;
		&lt;/div&gt;
		&lt;div id="sidebar"&gt;

			&lt;!-- sidebar here --&gt;

		&lt;/div&gt;
		&lt;div id="footer"&gt;

			&lt;!-- footer here --&gt;

		&lt;/div&gt;
		&lt;div class="clearfix"&gt;&lt;/div&gt;
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>I know that&#8217;s a lot, but it&#8217;s all pretty basic stuff, and really besides the point of what the tutorial is about, so it&#8217;s not a huge deal. Basically some header info for a WordPress blog, a short header (that&#8217;ll become a nice header picture), and a short loop to display the content.</p>
<p>Next up, we&#8217;ll stick in a static Sidebar. Replace the &#8217;sidebar here&#8217; comment with:</p>
<pre name="code" class="php">&lt;ul&gt;
	&lt;li&gt;&lt;h3&gt;Subscribe&lt;/h3&gt;
		&lt;ul&gt;
			&lt;li&gt;&lt;a href="#"&gt;Subscribe via RSS&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href="#"&gt;Subscribe via Email&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href="#"&gt;Subscribe via FeedBurner&lt;/a&gt;&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/li&gt;
	&lt;li id="ads"&gt;&lt;h3&gt;Ads&lt;/h3&gt;
		&lt;ul&gt;
			&lt;li&gt;Advertise Here&lt;/li&gt;
			&lt;li&gt;Advertise Here&lt;/li&gt;
			&lt;li&gt;Advertise Here&lt;/li&gt;
			&lt;li&gt;Advertise Here&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/li&gt;
&lt;/ul&gt;</pre>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/112_wordPressFooter/res/unstyledsidebar.png" alt="" /></div>
<p>This is just, once again your regular sidebar. The ads we&#8217;ll make pretty later on in CSS code&#8230; Now we need the interesting part: the footer.</p>
<p>Like I said above, it&#8217;s becoming more and more prominent for Websites to have more informative and useful footers, rather than just a dumb Copyright name bar. So instead, we&#8217;re gonna fill it with content to direct readers to other pages. After all, content is king, right? This is the footer:</p>
<pre name="code" class="php">&lt;div&gt;&lt;h3&gt;Archives&lt;/h3&gt;
	&lt;ul&gt;&lt;?php wp_get_archives('type=monthly'); ?&gt;&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;&lt;h3&gt;Recent Posts&lt;/h3&gt;
    &lt;ul&gt;&lt;?php wp_get_archives('type=postbypost&#038;limit=10'); ?&gt;&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;&lt;h3&gt;About&lt;/h3&gt;
    &lt;p&gt;Hello, this blog is about a whole lot of junk. In fact, the description is pretty self explanitory: &lt;?php bloginfo('description'); ?&gt;. Enjoy your stay and we hope to see you back!&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;&lt;h3&gt;Links&lt;/h3&gt;
    &lt;ul&gt;&lt;?php wp_list_bookmarks('title_li=&#038;categorize=0'); ?&gt;&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="clearfix"&gt;&lt;/div&gt;</pre>
<p>Finally something interesting!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/112_wordPressFooter/res/unstyledfooter.png" alt="" /></div>
<p>Already we&#8217;ve got a footer that&#8217;s interesting. It doesn&#8217;t look much like a footer right now though, so let&#8217;s jump into the CSS!</p>
<h3>Step 2 &#8211; CSS</h3>
<p>Let&#8217;s get some prettiness going. Open style.css, and let&#8217;s get coding!</p>
<pre name="code" class="css">*{
	margin: 0;
	padding: 0;
	outline: 0;
}

body{
	background-color: #e3e3e3;
	padding: 30px 0;
	font: 12px "Lucida Grande", Lucida, Verdana, sans-serif;
}

.clearfix{
	display: block;
	clear: both;
	width: 1px;
}

#wrapper{
	width: 960px;
	margin: 0 auto;
	background: #fff;
	padding: 30px 0;
}</pre>
<p>We start off with some basic &#8216;reset&#8217; info, that aligns everything, makes the text normal, and defines a class that is our &#8216;clearfix&#8217;.</p>
<p>Now we&#8217;ll fix up the header. Remember the images folder you unzipped at the start? There&#8217;s an image in there called &#8216;mywebsite.png&#8217;. I was lazy, and made an image with some effects for this part.</p>
<p> It wont display the name of your blog, but it&#8217;ll display &#8216;My Website&#8217;. This technique shows how image replacement is done via CSS safely&#8230;</p>
<pre name="code" class="css">h1{
	margin: 40px auto 0;
	width: 930px;
	position: relative;
	top: -30px;
}

h1 a{
	color: #b3b7ba;
	text-decoration: none;
	display: block;
	width: 203px;
	height: 38px;
	text-indent: -999em;
	background: url(images/mywebsite.png) no-repeat right top;
	float: right;
}</pre>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/112_wordPressFooter/res/header.png" alt="" /></div>
<p>As you can see, the &#8216;a&#8217; has been expanded and blocked to fit the background image of the &#8216;My Website&#8217; image. This is a quick and dirty way to do it &#8211; also cross browser I believe!</p>
<p>Moving on, we now style the content section:</p>
<pre name="code" class="css">#content{
	padding: 30px;
	float: left;
	width: 650px;
}

h2{
	letter-spacing: -2px;
	text-transform: uppercase;
	font-size: 16px;
	margin-bottom: 10px;
}

.entry{
	margin-bottom: 20px;
}

.entry a{
	color: #164774;
	text-decoration: none;
}
</pre>
<p>Already the layout starts to form, but the Sidebar and Footer still need some work, and de-squashifying!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/112_wordPressFooter/res/content.png" alt="" /></div>
<p>We can do some of the styling to the Sidebar, but not all of it. Seeing as we&#8217;re aiming for universal widgets, most of the styling for the Sidebar Widgets can be done along with the Footer&#8217;s.</p>
<pre name="code" class="css">#sidebar{
	float: left;
	width: 220px;
	margin: 0 10px;
	padding-top: 30px;
}

#sidebar>ul>li{
	margin-bottom: 10px !IMPORTANT;
}

#ads li{
	display: inline-block;
	width: 100%;
	background: #f7f7f7;
	height: 50px;
	text-align: center;
	margin-bottom: 10px;
	color: gray;
	line-height: 50px;
	border: 1px solid;
}</pre>
<p>If you refresh, you&#8217;ll notice it&#8217;s still a bit squashy. Let&#8217;s fix that up with some styling for the Footer and Sidebar</p>
<pre name="code" class="php">#footer{
	clear: both;
}

#footer div, #sidebar>ul>li{
	float: left;
	width: 220px;
	margin: 0 10px;
	background: url(images/modalBox.png) repeat-y center top;
	color: #fff;
}

#footer p{
	padding: 10px;
}

#footer a, #sidebar a{
	color: #fff;
	text-decoration: none;
}

#footer h3, #sidebar h3{
	margin-bottom: 10px;
	background: url(images/modalBoxHeader.png) no-repeat center top;
	height: 14px;
	font-size: 12px;
	text-align: center;
	color: #fff;
	font-weight: normal;
	text-shadow: #000 1px 1px 3px;
}

#footer ul, #sidebar ul>li>ul{
	list-style: none;
	padding: 10px;
	background: url(images/modalBoxFooter.png) no-repeat center bottom;
}

#footer ul li{
	padding-bottom: 5px;
}</pre>
<p>That&#8217;s a heck of a block! But now your WordPress blog should look a lot more interesting! That also splits the 4 footer sections into 4 columns &#8211; for nice, neat UI!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/112_wordPressFooter/res/allStyled.png" alt="" /></div>
<p>All done! That&#8217;s the manual part of the site done. Now that that&#8217;s done though, we&#8217;re going to take this one step further and make it 100% manageable through WordPress Admin.</p>
<h3>Step 3 &#8211; Making it Dynamic</h3>
<p>Dynamic Sidebars are a fantastic built-in function of WordPress. They&#8217;re easy to use, and basically provides a way to manage more of your content through a Web Interface. Let&#8217;s make our index.php sidebar-compatible.</p>
<p>Firstly, we&#8217;ll replace the huge chunks of code that made up our Sidebar and Footer with dynamic code. Replace everything within the #sidebar div>ul with:</p>
<pre name="code" class="php">&lt;?php if(function_exists('dynamic_sidebar') &#038;&#038; dynamic_sidebar(Sidebar)) : ?&gt;
&lt;?php endif; ?&gt;</pre>
<p>And replace everything between the #footer div with:</p>
<pre name="code" class="php">&lt;?php if(function_exists('dynamic_sidebar') &#038;&#038; dynamic_sidebar(Footer)) : ?&gt;
&lt;?php endif; ?&gt;</pre>
<p>If you refresh your page, everything&#8217;ll disappear. Create a new file in the directory called functions.php, and let&#8217;s get coding!</p>
<p>We need to create two functions &#8211; both &#8216;register_sidebar()&#8217;. Register one for the actual Sidebar, and one for the Footer.</p>
<pre name="code" class="php">&lt;?php
	if(function_exists('register_sidebar')){
		register_sidebar(array('name' =&gt; 'Sidebar',
			'before_widget' =&gt; '&lt;li&gt;',
			'after_widget' =&gt; '&lt;/li&gt;',
			'before_title' =&gt; '&lt;h3&gt;',
			'after_title' =&gt; '&lt;/h3&gt;',
		));
		register_sidebar(array('name' =&gt; 'Footer',
			'before_widget' =&gt; '&lt;div&gt;',
			'after_widget' =&gt; '&lt;/div&gt;',
			'before_title' =&gt; '&lt;h3&gt;',
			'after_title' =&gt; '&lt;/h3&gt;',
		));
	}
?&gt;</pre>
<p>Those arrays are the series of information to attach to each sidebar. The name (so we can select the different ones in WordPress Admin), and the information to put before/after(container) each widget, and before/after each header. Because our code is specific to h3s, we need to tell it to wrap in h3s. Our footer sections are divs, so we need to wrap them in divs instead of the default lis. Simple! If you refresh, you may or may not find content waiting for you. If not, we&#8217;ll fix that in the next step.</p>
<h3>Step 4 &#8211; The Sidebar Contents</h3>
<p>As I said, there may or may not be content waiting. This is how you edit it. Go the WP Dashboard, and visit the widgets page via design (For WP 2.3+) (Dashboard>Design>Widgets). In the right hand column, there should be your sidebar!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/112_wordPressFooter/res/sidebars.png" alt="" /></div>
<p>You can now skip between them, save changes, revisit your page and have the content edited easily via a Web Interface instead of trawling through code! Just make sure your &#8216;Footer&#8217; Sidebar only has 4 widgets max, as otherwise it&#8217;ll start bleeding onto the next line.</p>
<h3>Wrap up</h3>
<p>So here takes up your last excuse not to have an interesting footer &#8211; you now know how to do it easily. It&#8217;s essentially an extra sidebar. This also saves a whole lot of precious space in your sidebar that you can fill with much more important stuff such as feeds, notices, etc. If you have an interesting footer yourself, let us know about it!</p>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/dont-ignore-your-wordpress-footer/feed/</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
		<item>
		<title>The Anatomy of GamePress &#8211; Part 1 (Updated)</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/the-anatomy-of-gamepress-part-1/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/the-anatomy-of-gamepress-part-1/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 10:05:47 +0000</pubDate>
		<dc:creator>Dan Harper</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[theme forest]]></category>
		<category><![CDATA[themeforest]]></category>

		<guid isPermaLink="false">http://nettuts.com/?p=1069</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/087_Gamepress/200X200.jpg" alt="The Anatomy of a template" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://themeforest.net/item/gamepress/17397">GamePress</a> is a &quot;Gaming News &amp; Reviews&quot; theme for WordPress and currently one of the most popular themes at <a href="http://themeforest.net">ThemeForest</a>. It is the most advanced theme I&#8217;ve created so far, and really pushes what the WordPress engine can do!</p>
<p><span id="more-1069"></span></p>
<div class="tutorial_image">
<a href="http://themeforest.net/item/gamepress/17397" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt=""></a></div>
<p><strong><em>Already read this article? Continue on to <a href="http://blog.themeforest.net/wordpress/the-anatomy-of-gamepress-part-2/">Part 2.</a></em></strong></p>
<p>This two-part series will focus on several key areas of the theme which seem to be some of the major selling points. I will also include examples of any important code used and provide links to various tutorials detailing similar techniques.</p>
<div class="tutorial_image"><a href="http://themeforest.net/item/gamepress/17397"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/3_preview.jpg" border="0" /></a></div>
<div class="tutorial_image"><a href="http://themeforest.net/item/gamepress/17397"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/purchase.jpg" alt="Purchase GamePress from ThemeForest for $40" border="0" /></a></div>
<h3>Homepage</h3>
<h4>Features Slider</h4>
<p>At the top of the homepage is one of my favourite parts of the theme &#8211; the Features Slider. It is inspired by the Flash slider at <a href="http://www.gamespot.com">GameSpot</a> &mdash; except this is created with jQuery&#8217;s Tabs plugin and CSS.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/4_features.jpg" border="0" /></div>
<p>The code for creating this is basically a combination of my <a href="http://nettuts.com/javascript-ajax/create-a-tabbed-interface-using-jquery/">&#8220;Create A Tabbed Interface Using jQuery&#8221;</a> tutorial here at NETTUTS (for the Tabs) and Chris Coyier&#8217;s <a href="http://css-tricks.com/creating-a-slick-auto-playing-featured-content-slider/">&#8220;Creating a Slick Auto-Playing Featured Content Slider&#8221;</a> at <a href="http://css-tricks.com/">CSS-Tricks</a> (for over-laying text on an image).</p>
<p>In fact, the only jQuery code I wrote for this was:</p>
<pre name="code" class="js">
$(document).ready(function() {
    $('.features > ul').tabs({ fx: { opacity: 'toggle' }, event: 'mouseover' }).tabs('rotate', 5000);
});
</pre>
<p>Which will fade the area when a tab is hovered over. The tabs will also auto-rotate every five seconds &#8211; who needs Flash? <img src='http://net.tutsplus.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Again, the actual WordPress code for pulling these posts from a &#8216;Features&#8217; category is based upon code avaliable in my <a href="http://nettuts.com/working-with-cmss/build-a-featured-posts-section-for-wordpress/">&#8220;Build a Featured Post Section for Wordpress&#8221;</a> tutorial:</p>
<pre name="code" class="php">
&lt;?php query_posts("cat=$gp_features_cat&amp;showposts=3&amp;orderby=date&amp;order=desc");
while (have_posts()) : the_post(); ?>
</pre>
<h4>Latest Headlines</h4>
<p>This section is basically what you&#8217;d see on any other WordPress theme. But there is also an image accompanying each post. This is achieved by making use of the &#8216;Custom Fields&#8217; option when writing a post:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/5_post-img.jpg" border="0" /></div>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/6_custom-field.jpg" border="0" /></div>
<p>To create a post image with custom fields on your own theme, you can use the following code inside your WordPress Loop:</p>
<pre name="code" class="php">
&lt;? $postimg = get_post_meta($post->ID, 'postimg',true); ?>
&lt;? if($postimg) { ?>&lt;img src="&lt;? echo $postimg; ?>" alt="" class="pimage" />&lt;? } ?>
</pre>
<p>The above code checks whether a custom field with the Key of <strong>postimg</strong> exists for the current post, and if so inserts the link into an image tag alongside the rest of the post.</p>
<p>For more information on using custom fields, check out <a href="http://justintadlock.com/archives/2007/10/27/wordpress-custom-fields-adding-images-to-posts">&#8220;WordPress Custom Fields&#8221;</a> by Justin Tadlock; and you may also be interested in <a href="http://blog.themeforest.net/wordpress/5-ways-enhance-your-wordpress-theme/">&#8220;5 Quick Ways To Enhance Your WordPress Theme&#8221;</a> over at the ThemeForest Blog.</p>
<h4>Older News</h4>
<p>The Latest Headlines section displays a user-defined number of posts, and below itis a more basic list of &#8216;older&#8217; posts:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/7_older.jpg" border="0" /></div>
<p>This is achieved by offsetting the number of posts get, using the following code instead of your normal WordPress Loop:</p>
<pre name="code" class="php">
&lt;?php query_posts("offset=$gp_latest_headlines");
while (have_posts()) : the_post(); ?>
</pre>
<p>$gp_latest_headlines is the number of posts listed in the Latest Headlines section.</p>
<p>You can do a lot with <strong>query_posts()</strong>, check out the <a href="http://codex.wordpress.org/Template_Tags/query_posts">WordPress Codex</a> for the full documentation on it.</p>
<h3>Reviews Page</h3>
<p>One of the main features is the Reviews Page Template, which displays all the reviews in a list, but also &#8216;expands&#8217; the first review to give more detail about it:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/1_review.jpg" border="0" /></div>
<p>The meta-data of the first review (Format, Release, Rating etc.) is all retrieved from a number of Custom Fields in the post:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/2_review-field.jpg" border="0" /></div>
<p>This is a perfect example of the numerous ways you can use Custom Fields &#8211; which are very easy to use in your own theme! For example, the following code is what&#8217;s used to retrieve the <em>release</em> (date) field:</p>
<pre name="code" class="php">
&lt;? $release = get_post_meta($post->ID, 'release',true); ?>
</pre>
<p>Of course, each field is entirely optional. If it wasn&#8217;t filled in, it wont display:</p>
<pre name="code" class="php">
&lt;? if($release) { ?>
    &lt;p>&lt;strong>Release:&lt;/strong> &lt;? echo $release; ?>&lt;/p>
&lt;? } ?>
</pre>
<p>We will look more into the Reviews &amp; Previews templates in Part 2.</p>
<h3>News Page</h3>
<p>Another Page Template provided with GamePress creates a main News page very similar to the Latest Headlines section on the homepage. However, I faced one problem: &#8220;How do I include an archives area to help sort posts by date, category and tag?&#8221; <br />
I didn&#8217;t want to force the admin of the site to use a widget in the sidebar as I did not want GamePress to feel like a &#8216;blog&#8217;.</p>
<p>After a lot of thought, I decided I needed some sort of &#8216;Archives&#8217; section at the top of the News page. But, it took up too much valuable &#8217;screen real-estate&#8217;:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/8_archive.jpg" border="0" /></div>
<p>My solution was to only show the &#8216;Archives&#8217; title-box, which when clicked, will cause the archive lists to slide out below. Notice that I also replaced the normal <strong>&raquo;</strong> in title-boxes to a <strong>+</strong> in order to add a subtle hint that the box is &#8216;clickable&#8217;</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/087_Gamepress/9_archive.gif" border="0" /></div>
<h3>Part Two</h3>
<p>This article continues over on the <a href="http://blog.themeforest.net/wordpress/the-anatomy-of-gamepress-part-2/">ThemeForest Blog</a> where we will look at:</p>
<ul>
<li>Theme Options</li>
<li>Two Colour Schemes</li>
<li>Single Pages</li>
<li>Archives</li>
</ul>
<ul class="webroundup">
<li>Subscribe to the <a href="http://feeds.feedburner.com/nettuts" title="NETTUTS RSS Feed">NETTUTS RSS Feed</a> for more daily web development tuts and articles.</li>
</ul>
<p>
<script type="text/javascript"><!--digg_url = "post permalink (not digg url)"; // -->
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/the-anatomy-of-gamepress-part-1/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Context Includes</title>
		<link>http://net.tutsplus.com/tutorials/wordpress/context-includes/</link>
		<comments>http://net.tutsplus.com/tutorials/wordpress/context-includes/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 13:54:01 +0000</pubDate>
		<dc:creator>Harley</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://nettuts.com/?p=1159</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/092_contextIncludes/200x200.png" alt="Context Includes" />
]]></description>
			<content:encoded><![CDATA[<p>The great thing about WordPress is that it doesn&#8217;t limit how content is displayed, but provides a &#8216;framework&#8217; of ways to do so. Even better, it&#8217;s possible to change the display according to the content. When writing this tutorial it was hard to explain what&#8217;s going on&#8230; But the best way is this: the post will be displayed within the loop according to its content &#8211; or contextual differences. Either way, it&#8217;s including specific files that match up to the category of the post.</p>
<p><span id="more-1159"></span></p>
<div class="tutorial_image">
<a href="http://nettuts.s3.amazonaws.com/092_contextIncludes/contextIncludes.zip"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_src_nm.jpg" alt=""></a><br />
<a href="http://nettuts.s3.amazonaws.com/092_contextIncludes/preview/index.html" target="_blank"><br />
<img src="http://nettuts.com/wp-content/themes/nettuts/site_images/button_demo_nm.jpg" alt=""></a></div>
<h3>Preface</h3>
<p>This tutorial assumes that you have a WordPress engine running on a server that you have access to upload files, download files and browse to. If you want to run a local server on your computer with a wordpress installation, there is a tutorial on that <a href="http://geeksaresexy.blogspot.com/2006/06/installing-wordpress-locally-under.html" title="geeks are sexy on how to install wordpress locally under XP">here for Windows</a>, and <a href="http://michaeldoig.net/4/installing-mamp-and-wordpress.htm" title="Michael Doig on installing wordpress locally under OS X">here for OS X</a>.</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/092_contextIncludes/res/final.png" alt="" /></div>
<p>Let me describe a little further in depth what we&#8217;ll be doing. Many WordPress sites are more than just a blog these days. For those that integrate a Blog, a News System, and a Portfolio, there are many ways to distinguish between each of these posts. For a start, the amount of meta information WordPress attaches to each post is monumental. Dates, Categories, Custom Fields, Options, Tags, amount of tags, etc. It goes on. By picking on one of these, you can manipulate WordPress to display certain things even when the context changes (I.e. different category name, different tag, etc). The method I&#8217;m about to teach figures out when a certain category is attached to a certain post, and then bring in a different file accordingly. Contextually! If the <em>context</em> is of a blog, display it like a blog post! If the <em>context</em> is of a portfolio item, display it like a portfolio item! So on, so forth. You get it. Let&#8217;s go!</p>
<h3>Step 1 &#8211; Basic Theme Necessities</h3>
<p>I&#8217;ve prepared a couple of files; style.css, index.php and some images (thanks TUTs sites!). We&#8217;ll be building off these to create our final product. <a href="res/preparedFiles.zip">Download them</a>, and place the folder in the wp-content/themes folder. Now go to the WordPress Dashboard, click &#8216;design&#8217; or &#8216;presentation&#8217; if you&#8217;re still living in the stone age, and select the &#8216;Context Files&#8217; theme. Great! Now it&#8217;s activated we can dive into editing the files and getting on with the tutorial.</p>
<h3>Step 2 &#8211; the WordPress Posts</h3>
<p>For the method to work, a group of posts need to have a certain category. For this, I gave a few of them the category &#8216;Blog&#8217;, some &#8216;theirNews&#8217;, and left the rest to be the portfolio group, without any specific category. Make sure to do this, or your results wont be too varied. So make sure your posts (for this tutorial at least) are grouped in some way. It&#8217;s vital!</p>
<h3>Step 3 &#8211; WordPress Code</h3>
<p>The functional way to describe what happens, is depending on the category, a specific file is included for the loop&#8217;s code. The heirarchy looks like this:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/092_contextIncludes/res/filestructure.png" alt="" /></div>
<p>A Blog post will end up looking like this:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/092_contextIncludes/res/blog.png" alt="" /></div>
<p>A News item will display like this:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/092_contextIncludes/res/news.png" alt="" /></div>
<p>And all other posts, or portfolio items will resemble this:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/092_contextIncludes/res/portfolio.png" alt="" /></div>
<p>Notice the little watermarks in the top right of each post? That&#8217;s proof our system will work!</p>
<p>Anyway. Between the body tags, we need a header and a loop. Add this:</p>
<pre name="code" class="php">&lt;div id="header"&gt;
    &lt;h1&gt;&lt;a href="&lt;?php bloginfo('url'); ?&gt;" title="Home"&gt;&lt;?php bloginfo('name'); ?&gt;&lt;/a&gt;&lt;/h1&gt;
    &lt;p class="description"&gt;&lt;?php bloginfo('description'); ?&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id="content"&gt;
    &lt;?php if(have_posts()) : while(have_posts()) : the_post();

    	//Getting the category and checking it against certain
    	//values to include the correct file goes here...

    endwhile;
    endif; ?&gt;
&lt;/div&gt;</pre>
<p>Next up, we need to get the category for each post. This uses some Custom WordPress/PHP syntax. Usually you could use get_the_category for the value, but you can get ANY category information via this method (goes under or replaces the comment in PHP):</p>
<pre name="code" class="php">foreach((get_the_category()) as $category){
    $categoryName = $category->cat_name.'';
}</pre>
<p>Now with that, we need to check this value against a value. If you named your categories &#8216;Blog&#8217; or &#8216;theirNews&#8217;, we can now check the $categoryName variable against exactly those names/values. Remember this is in the loop, so this check is made for each individual post.</p>
<pre name="code" class="php">if($categoryName == 'Blog'){ include(TEMPLATEPATH.'/blogTemplate.php'); }
elseif($categoryName == 'theirNews'){ include(TEMPLATEPATH.'/newsTemplate.php'); }
else(include(TEMPLATEPATH.'/portfolioTemplate.php'));</pre>
<p>Each line of the 3 above is relatively the same. The PHP &#8216;==&#8217; means &#8216;is equal to&#8217;. It&#8217;s two =&#8217;s because when using only one = defines a variable. Not what we want. If, elseif, and else are a few conditional PHP tags. You can use multiple elseif statements if you wish to have more than three files!</p>
<p>With the PHP done, we can now create the actual files that are included above. What&#8217;s interesting about this template is that you can keep the entire loop, category, and includes all within one set of PHP tags. Efficiency!</p>
<h4>blogTemplate.php</h4>
<p>These files are basically what goes in the loop, consisting of loop template tags. So we can assign each category with the top right watermark, a different class is applied to each different category file. Otherwise, this is all basic WordPress stuff. Create a new file called &#8216;blogTemplate.php&#8217; in the theme folder, and fill it up with some PHP goodness!</p>
<pre name="code" class="php">&lt;div class="post blog"&gt;
&lt;h2&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p class="postInfo"&gt;Posted by &lt;?php the_author(); ?&gt; | Filed under &lt;?php the_category(' &#038; '); ?&gt;&lt;/p&gt;
&lt;?php the_content(''); ?&gt;
&lt;p class="postMetaData"&gt;
	&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;Read More&lt;/a&gt; |
	&lt;?php comments_popup_link('Comments(0)','Comments(1)','Comments(%)'); ?&gt; |
	&lt;?php the_time('F d, Y'); ?&gt;
&lt;/p&gt;
&lt;/div&gt;</pre>
<p>Just one thing to note. I know it&#8217;s very bad practice for SEO reasons, but the_content(&#8221;)  has the 2 &#8217;s so that no &#8216;read more&#8217; is displayed. The &#8216;Read More&#8217; link in the postMetaData makes up for this!</p>
<h4>newsTemplate.php</h4>
<p>This is pretty minimalistic. The header is smaller too!</p>
<pre name="code" class="php">&lt;div class="post news"&gt;
&lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;/h3&gt;
&lt;?php the_content(''); ?&gt;
&lt;p class="postMetaData"&gt;&lt;a href="#"&gt;Visit Source&lt;/a&gt; | &lt;?php the_time('F d, Y'); ?&gt;&lt;/p&gt;
&lt;/div&gt;</pre>
<h4>portFolio.php</h4>
<p>Finally, the last sub template file.</p>
<pre name="code" class="php">&lt;div class="post portfolio"&gt;
&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/images/portfolio.png" alt="" /&gt;
&lt;h2&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;?php the_content(''); ?&gt;
&lt;p class="postMetaData"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;View Project&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;</pre>
<p>And that&#8217;s all the PHP/HTML you&#8217;ll be needing! If you load your WordPress page, it&#8217;ll now resemble something like below:</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/092_contextIncludes/res/precss.png" alt="" /></div>
<p>Note you can already see the differences in each post!</p>
<h3>Step 4 &#8211; CSS</h3>
<p>Now to make it pretty! We&#8217;ll start off with some defaulting code. This is to set it to a base look, get rid of stuff we don&#8217;t want and style general tags (i.e. headers, etc).</p>
<pre name="code" class="css">a{
	text-decoration: none;
	color: #b93a00;
}

*{
	margin: 0;
	padding: 0;
}

body{
	background: #000;
	color: #5b5b5b;
	font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
	font-size: 75%;
}

h1, h2, h3, h1 a, h2 a, h3 a{
	font-family:"Trebuchet MS", Arial, Helvetica;
	color: #fff;
	letter-spacing: -2px;
	text-decoration: none;
}

h1 a:hover, h2 a:hover, h3 a:hover{
	color: #8b8b8b;
}

h2{
	font-size: 35px;
	margin-bottom: 10px;
}

h3{
	font-size: 20px;
	color: #a8a8a8;
	letter-spacing: -1px;
	padding-bottom: 20px;
}</pre>
<p>Now we need some structure to our page.</p>
<pre name="code" class="css">#wrapper{
	margin: 0 auto;
	width: 500px;
	font-size: 11px;
}

#header{
	height: 150px;
	font-family: Georgia, 'Times New Roman', Times, serif;
	border-bottom: 1px solid;
	border-color: #222;
}

#content{
	padding-top: 20px;
}

.post{
	margin-bottom: 40px;
	min-height: 150px;
}</pre>
<p>Next we&#8217;ll add the little blackground watermarks in:</p>
<pre name="code" class="css">.blog{
	background: url(images/blogbg.png) no-repeat top right;
}

.portfolio{
	background: url(images/portfoliobg.png) no-repeat top right;
	min-height: 150px;
}

.news{
	background: url(images/newsbg.png) no-repeat top right;
	padding-right: 100px;
}</pre>
<p>Our theme is taking shape! All that&#8217;s left is some image styling and the styling of the postMetaData!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/092_contextIncludes/res/takingshape.png" alt="" /></div>
<pre name="code" class="css">#header h1{
	font-size: 50px;
	padding-top: 30px;
}

#header p.description{
	font-style: italic;
	font-size: 16px;
}

.post img{
	float: left;
	padding-right: 10px;
	padding-bottom: 20px;

}

.post p{
	padding-bottom: 15px;
}

.postInfo{
	padding: 10px;
}

.postMetaData{
	padding: 10px;
	background: #141414;
	margin: 10px 0;
	width: 480px;
	display: block;
	clear: both;
}

.postMetaData a{
	color: #06f;
}</pre>
<p>The last section of code needed, your theme should now look complete! This tutorial teaches you a couple of things. A versitile way to get category info, how to use this in conjunction with conditional tags, and grouping PHP!</p>
<div class="tutorial_image"><img src="http://nettuts.s3.amazonaws.com/092_contextIncludes/res/final.png" alt="Final" /></div>
<h3>You Also Might Like&#8230;</h3>
<div class="article-preview" id="post-981">
					<a href="http://nettuts.com/javascript-ajax/adding-to-our-leopard-desktop-with-jquery/"><img src="http://nettuts.s3.amazonaws.com/082_leopard2/200x200.png" alt="Leopard With jQuery" /></a></p>
<p>					<a href="http://nettuts.com/javascript-ajax/adding-to-our-leopard-desktop-with-jquery/"><br />
<h2>Adding to Our Leopard Desktop with jQuery</h2>
<p></a><br />
					<small>in <a href="http://nettuts.com/category/javascript-ajax/" title="View all posts in Javascript / AJAX" rel="category tag">Javascript / AJAX</a> by <a href="http://nettuts.com/author/harley/" title="Posts by Harley">Harley</a></small></p>
<div class="content">
<p><a href="http://nettuts.com/javascript-ajax/leopard-desktop-in-jquery-using-jqdock/">Last Week</a> I got you all to create a neat looking Dashboard/Desktop. You guys are gonna totally FLIP when you hear what&#8217;s in this jam packed tutorial! More focus on the Dashboard (I swear it&#8217;s cooler than it sounds, and requires a lot of code), and I&#8217;ll even go into how to create a stack (seperate from the dock, sorry jqDock doesn&#8217;t like nestled &lt;ul>s), and some extra little bits to make it all click.</p>
<p> <a href="http://nettuts.com/javascript-ajax/adding-to-our-leopard-desktop-with-jquery/#more-981" class="more-link">Continue Reading</a></p>
</p></div>
<div style="clear:both"></div>
</p></div>
<div class="article-separator"></div>
<div class="article-preview" id="post-860">
					<a href="http://nettuts.com/javascript-ajax/leopard-desktop-in-jquery-using-jqdock/"><img src="http://nettuts.s3.amazonaws.com/076_jQueryDashboard/200x200.png" alt="jQuery Dashboard" /></a></p>
<p>					<a href="http://nettuts.com/javascript-ajax/leopard-desktop-in-jquery-using-jqdock/"><br />
<h2>Leopard Desktop with jQuery using jqDock</h2>
<p></a><br />
					<small>in <a href="http://nettuts.com/category/javascript-ajax/" title="View all posts in Javascript / AJAX" rel="category tag">Javascript / AJAX</a> by <a href="http://nettuts.com/author/harley/" title="Posts by Harley">Harley</a></small></p>
<div class="content">
<p>
    jQuery adds a whole lot of cool functionality to your websites. It can do a range of things, from animation to AJAX. It&#8217;s usually frowned upon to rely heavily on jQuery to design your sites, but it&#8217;s fun to go wild every now and then. In this tutorial I&#8217;ll teach you how to use jQuery to create a completely coded Dashboard, just like Leopard! This can be handy in hiding a whole lot of gadgets or widgets you don&#8217;t have space for!</p>
<p> <a href="http://nettuts.com/javascript-ajax/leopard-desktop-in-jquery-using-jqdock/#more-860" class="more-link">Continue Reading</a></p>
</p></div>
<div style="clear:both"></div>
</p></div>
<div class="article-separator"></div>
<div class="article-preview" id="post-733">
					<a href="http://nettuts.com/html-css-techniques/5-time-saving-cssedit-tips/"><img src="http://nettuts.s3.amazonaws.com/069_cssEditTips/200x200.png" alt="5 Time-Saving CSSEDIT TIPS" /></a></p>
<p>					<a href="http://nettuts.com/html-css-techniques/5-time-saving-cssedit-tips/"><br />
<h2>5 Time Saving CSSEdit Tips</h2>
<p></a><br />
					<small>in <a href="http://nettuts.com/category/html-css-techniques/" title="View all posts in HTML / CSS" rel="category tag">HTML / CSS</a> by <a href="http://nettuts.com/author/harley/" title="Posts by Harley">Harley</a></small></p>
<div class="content">
<p><a href="http://cssedit.com/">CSSEdit</a> is another fantastic web dev app, which takes Apple&#8217;s WebKit by the reigns to deliver a fantastic real-time visual CSS editing experience. But that&#8217;s just it! People only know it as a visual CSS editor, when it is actually much more! I use these 5 fantastic tips to keep my work flow fast and smooth.</p>
<p>             <a href="http://nettuts.com/html-css-techniques/5-time-saving-cssedit-tips/#more-733" class="more-link">Continue Reading</a></p>
</p></div>
<div style="clear:both"></div>
</p></div>
<div class="article-separator"></div>
</p></div>
<div class="article-preview" id="post-149">
					<a href="http://nettuts.com/working-with-cmss/build-a-newspaper-theme-with-wp_query-and-the-960-css-framework/"><img src="http://nettuts.s3.amazonaws.com/034_powerOfWP/200x200.png" alt="The Power of WordPress" /></a></p>
<p>					<a href="http://nettuts.com/working-with-cmss/build-a-newspaper-theme-with-wp_query-and-the-960-css-framework/"><br />
<h2>Build a Newspaper Theme With WP_Query and the 960 CSS Framework</h2>
<p></a></p>
<p>					<small>in <a href="http://nettuts.com/category/working-with-cmss/" title="View all posts in Working with CMS's" rel="category tag">Working with CMS&#8217;s</a> by <a href="http://nettuts.com/author/harley/" title="Posts by Harley">Harley</a></small></p>
<div class="content">
<p>
 WP_Query is a powerful tool to control what comes out of your loop. Today I&#8217;m going to teach you all how to use it to make a 3 columned newspaper theme that has all your main blog posts in the main column, and off to the side a set of posts with a certain category. We&#8217;ll be using the <strong>960 CSS framework</strong> for the basic layout and reset of our theme, it will chop a lot of work off what&#8217;s needed!</p>
<p> <a href="http://nettuts.com/working-with-cmss/build-a-newspaper-theme-with-wp_query-and-the-960-css-framework/#more-149" class="more-link">Continue Reading</a></p>
</p></div>
<div style="clear:both"></div>
<p></p>
<ul class="webroundup">
<li>Subscribe to the <a href="http://feeds.feedburner.com/nettuts" title="NETTUTS RSS Feed">NETTUTS RSS Feed</a> for more daily web development tuts and articles.</li>
</ul>
<p>
<script type="text/javascript"><!--digg_url = "post permalink (not digg url)"; // -->
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://net.tutsplus.com/tutorials/wordpress/context-includes/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
	</channel>
</rss>
<!--
This site's performance optimized by W3 Total Cache:

W3 Total Cache improves the user experience of your blog by caching
frequent operations, reducing the weight of various files and providing
transparent content delivery network integration.

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 4/21 queries in 0.025 seconds using memcached
Content Delivery Network via 

Served from: psdtutsplus.com @ 2009-11-21 16:33:41 -->