<?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>Stefan Crowe</title>
	<atom:link href="http://stefancrowe.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://stefancrowe.co.uk</link>
	<description>PHP, MySQL and Javascript Developer (UK)</description>
	<lastBuildDate>Thu, 28 Jun 2012 11:05:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Adding custom categories to WordPress</title>
		<link>http://stefancrowe.co.uk/adding-custom-categories-to-wordpress/129/</link>
		<comments>http://stefancrowe.co.uk/adding-custom-categories-to-wordpress/129/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 15:42:45 +0000</pubDate>
		<dc:creator>Stefan Crowe</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[custom taxonomies]]></category>

		<guid isPermaLink="false">http://stefancrowe.co.uk/?p=129</guid>
		<description><![CDATA[Note: You will be required to make some basic changes to code to carry out this tutorial &#8211; make sure you create backups before making any changes to your website code Most people don&#8217;t realise that WordPress isn&#8217;t just a blogging paltform, but that it is also a powerful content management system (CMS) in general. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note: You will be required to make some basic changes to code to carry out this tutorial &#8211; make sure you create backups before making any changes to your website code</strong></p>
<p>Most people don&#8217;t realise that WordPress isn&#8217;t just a blogging paltform, but that it is also a powerful content management system (CMS) in general. One of the many key features that enhances WordPress&#8217; capabilities as a CMS is the ability to add your own categories and tags. This allows you greater control over the navigation and layout of your content throughout the WordPress site.</p>
<p>An example of when custom taxonomies (a fancy way of saying categories and tags) may be of use is if you imagine a sports website. You might use the normal categories to distinguish between types of posts (e.g. news, match reviews, opinion pieces, etc.), but what if you want to associate particular players or teams to individual posts?</p>
<p>This is where custom categories and tags come into play; with this functionality you can create a whole new category for your teams, and you could even add a new tags section for players.</p>
<h3>Adding a custom category</h3>
<p>There should only be one file you need to edit for this process &#8211; it is called <code>functions.php</code> and is located in your theme directory (<code>/wp-content/themes/&lt;your theme&gt;/functions.php</code>). Don&#8217;t worry if there isn&#8217;t a file by this name here, simply create a plain text file and rename it to <code>functions.php</code>.</p>
<p>Add the following code to the file:</p>
<pre>//create new category taxonomy "Teams"
function create_new_taxonomies()
{
	// Hierarchical (e.g. categories)
	$labels = array(
		'name' =&gt; 'Teams',
		'singular_name' =&gt; 'Team',
		'search_items' =&gt;  'Search Teams',
		'all_items' =&gt; 'All Teams',
		'edit_item' =&gt; 'Edit Teams',
		'update_item' =&gt; 'Update Team',
		'add_new_item' =&gt; 'Add New Team',
		'new_item_name' =&gt; 'New Team Name'
	); 	

	register_taxonomy(
		'teams', 'post', array(
		'hierarchical' =&gt; true,
		'labels' =&gt; $labels,
		'show_ui' =&gt; true,
		'query_var' =&gt; true,
		'rewrite' =&gt; array( 'slug' =&gt; 'team' )
	));
}
add_action( 'init', 'create_new_taxonomies', 0 );</pre>
<blockquote><p>If you are happy with not knowing the intricacies of this code, then simply change references of &#8216;teams&#8217; and &#8216;team&#8217; to suit your custom category and you&#8217;re good to go.</p></blockquote>
<p>Now, let&#8217;s take a look at this code in finer detail, starting (somewhat confusingly) with the last line:</p>
<pre>add_action( 'init', 'create_new_taxonomies', 0 );</pre>
<p>This tells WordPress to call the function <code>create_new_taxonomies()</code> upon loading. This function (seen on line 2) contains the code to create our custom category taxonomy. This is split into two parts, the first is a list:</p>
<pre>$labels = array(
	'name' =&gt; 'Teams',
	'singular_name' =&gt; 'Team',
	'search_items' =&gt;  'Search Teams',
	'all_items' =&gt; 'All Teams',
	'edit_item' =&gt; 'Edit Teams',
	'update_item' =&gt; 'Update Team',
	'add_new_item' =&gt; 'Add New Team',
	'new_item_name' =&gt; 'New Team Name'
);</pre>
<p>This list is an array of variables, these are to replace the text labels used throughout WordPress to let users know how to deal with your new taxonomy. I have included a few examples in the code, the full list can be seen on the official WordPress Codex page for <a href="http://codex.wordpress.org/Function_Reference/register_taxonomy#Arguments">register_taxonomy</a>. Finally, with our labels prepared, we proceed to the final stage of the process:</p>
<pre>register_taxonomy(
	'Teams', 'post', array(
		'hierarchical' =&gt; true,
		'labels' =&gt; $labels,
		'show_ui' =&gt; true,
		'query_var' =&gt; true,
		'rewrite' =&gt; array( 'slug' =&gt; 'team' )
	)
);</pre>
<p>This tells WordPress to create a new taxonomy. The first two parameters: <code>'Teams', 'post'</code> are the name for the new taxonomy and the post type (in this case just normal posts, you could instead put &#8216;page&#8217; to have it usable on pages or other custom types).</p>
<p>The third parameter is an array of options, here you can customise the functionality of the new taxonomy. For the code above, here is a quick explanation of each option in respective order:</p>
<ul>
<li><strong>hierarchial</strong>: if true it behaves like categories, otherwise it acts more like tags</li>
<li><strong>labels</strong>: here we insert the labels list we created earlier</li>
<li><strong>show_ui: </strong>whether or not to display management controls for this taxonomy in your admin panel</li>
<li><strong>query_var: </strong>for advanced users &#8211; allows you to easily call posts of this taxonomy type using it&#8217;s name in custom post queries</li>
<li><strong>rewrite: </strong>allows the taxonomy to have it&#8217;s own seo-friendly permalink structure (<code>www.yourwebsite.com/&lt;slug&gt;</code>)</li>
</ul>
<h3>Adding a custom tag taxonomy</h3>
<p>You can also make the taxonomy emulate tags rather than categories by changing the line <code>'hierarchical' =&gt; true</code> to <code>'hierarchical' =&gt; false</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://stefancrowe.co.uk/adding-custom-categories-to-wordpress/129/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Welcome to my site!</title>
		<link>http://stefancrowe.co.uk/welcome-to-my-site/121/</link>
		<comments>http://stefancrowe.co.uk/welcome-to-my-site/121/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 15:24:22 +0000</pubDate>
		<dc:creator>Stefan Crowe</dc:creator>
				<category><![CDATA[Digressions]]></category>

		<guid isPermaLink="false">http://stefancrowe.co.uk/?p=121</guid>
		<description><![CDATA[I know it seems terribly generic, but I&#8217;d like to make my first post* a quick little greeting to anyone who should happen to wander across this website. Over time I will be adding new pages to the blog and tutorial sections of this site, as well as providing updates regarding some of the projects [...]]]></description>
			<content:encoded><![CDATA[<p>I know it seems terribly generic, but I&#8217;d like to make my first post* a quick little greeting to anyone who should happen to wander across this website.</p>
<p>Over time I will be adding new pages to the blog and tutorial sections of this site, as well as providing updates regarding some of the projects I&#8217;ve worked on. I may also occasionally deviate from programming-related subjects and intersperse opinion or news posts, of interest to me, amongst them. These may be either nerdy or pointless (or maybe even both) in nature and not to everyone&#8217;s taste, but feel free to voice your own thoughts (within reason) in the comments.</p>
<p>All-in-all, I hope to let people know <a title="About me" href="http://stefancrowe.co.uk/about-me/">about me</a>, what I have done and am doing, and also provide information that will be of use to <em>someone</em> out there and if not, at least I&#8217;ll have something to look back on and laugh at when I&#8217;m older&#8230;</p>
<p>* <em>This is a lie. My first post was a JavaScript tutorial about <a title="Clear textbox on click using JavaScript" href="http://stefancrowe.co.uk/clear-textbox-on-click-using-javascript/78/">clearing text from a textbox on click</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://stefancrowe.co.uk/welcome-to-my-site/121/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clear textbox on click using JavaScript</title>
		<link>http://stefancrowe.co.uk/clear-textbox-on-click-using-javascript/78/</link>
		<comments>http://stefancrowe.co.uk/clear-textbox-on-click-using-javascript/78/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 18:34:58 +0000</pubDate>
		<dc:creator>Stefan Crowe</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://stefancrowe.co.uk/?p=78</guid>
		<description><![CDATA[It&#8217;s such a simple design choice: you want to have some default text in a textbox as an indication to the purpose of the form field. This is commonly used in search boxes to prompt the user and minimise clutter from excess labels. In fact, you can see an example right here on this website [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s such a simple design choice: you want to have some default text in a textbox as an indication to the purpose of the form field. This is commonly used in search boxes to prompt the user and minimise clutter from excess labels. In fact, you can see an example right here on this website (see the search form to the right of the main navigation).</p>
<p>The problem is, when a user clicks the textbox they then have to manually delete the default text you put there. This is adding unnecessary work for your users who presumably want the quickest and smoothest interface possible. The ideal solution is to automatically clear the textbox on click by the user. This can easily be accomplished using a little bit of basic JavaScript on the HTML form element:</p>
<pre>&lt;input onclick="if(this.value == 'search...')this.value = '';" onblur="if(this.value == '')this.value = 'search...';" type="text" value="search..." /&gt;</pre>
<p>Simply replace the three occurrences of &#8220;search&#8230;&#8221; with the text you want to display by default. Note: make sure all three strings match or it will fail to work correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://stefancrowe.co.uk/clear-textbox-on-click-using-javascript/78/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: stefancrowe.co.uk @ 2013-06-20 01:18:37 -->