<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Justin Tadlock</title>
	
	<link>http://justintadlock.com</link>
	<description>Life, Blogging, and WordPress</description>
	<lastBuildDate>Thu, 02 Jul 2009 03:10:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/JustinTadlock" type="application/rss+xml" /><feedburner:emailServiceId>JustinTadlock</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>How to filter a WordPress theme’s ‘more link’ text</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/tYGk2rOYi_s/how-to-filter-a-wordpress-themes-more-link-text</link>
		<comments>http://justintadlock.com/archives/2009/07/01/how-to-filter-a-wordpress-themes-more-link-text#comments</comments>
		<pubDate>Thu, 02 Jul 2009 03:10:40 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1737</guid>
		<description><![CDATA[A tutorial on how to create custom more link text for your WordPress theme using <code>the_content_more_link</code> filter hook.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">C</span>hanging the <em>more link</em> in a WordPress theme is easy.  Just open your theme files and change it.  But, if you&#8217;re writing a plugin to change this or want to preserve your theme&#8217;s code (e.g., child themes), you need a way to easily edit this.</p>
<p>I&#8217;ve seen some themes add their own more link filter hook, but this is unnecessary because WordPress 2.8 introduced <code>the_content_more_link</code> filter hook.  Maybe this post will help those theme authors cut back on an extra filter hook when it&#8217;s not needed.</p>
<p>This will allow us to easily overwrite the default.</p>
<h2>What is the more link?</h2>
<p>When writing a WordPress post, you can cut the text off at any point by adding in this code:</p>
<pre><code>&lt;!--more--></code></pre>
<p>If you&#8217;re using a theme that shows the standard full post on the home/blog page of your site, this will cut the article short at the point you added the code.  It will also add a link to the single-post view where the reader can continue reading the post.</p>
<h2>Using the_content_more_link filter hook</h2>
<p>What we want to do is change our theme&#8217;s more link text, but we need to do this the appropriate way, and the appropriate way means not hacking up your theme author&#8217;s code.</p>
<p>Let&#8217;s assume our theme&#8217;s more link outputs &#8220;(more&#8230;)&#8221; when we add the <code>&lt;!--more--></code> link within the post editor.  Maybe we don&#8217;t like that message too much.  We&#8217;d like to change it to read &#8220;Continue reading &rarr;&#8221; instead.</p>
<p>Open your theme&#8217;s (or child theme&#8217;s) <code>functions.php</code> file and paste this code in:</p>
<pre><code>&lt;?php

add_filter( 'the_content_more_link', 'my_more_link', 10, 2 );

function my_more_link( $more_link, $more_link_text ) {
	return str_replace( $more_link_text, 'Continue reading &amp;rarr;', $more_link );
}

?></code></pre>
<p>That&#8217;s all there is to it.  Enjoy your custom more link text.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/tYGk2rOYi_s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/07/01/how-to-filter-a-wordpress-themes-more-link-text/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/07/01/how-to-filter-a-wordpress-themes-more-link-text</feedburner:origLink></item>
		<item>
		<title>Sliding Panel: WordPress Plugin</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/Wn_zGYDj0vQ/sliding-panel-wordpress-plugin</link>
		<comments>http://justintadlock.com/archives/2009/06/25/sliding-panel-wordpress-plugin#comments</comments>
		<pubDate>Fri, 26 Jun 2009 04:09:26 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1725</guid>
		<description><![CDATA[A fully-widgetized, jQuery-based sliding panel for your WordPress-powered blog.  This widget area allows you to add whatever content you want to your panel.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">E</span>ver since I <a href="http://themehybrid.com/archives/2009/04/theme-hybrids-new-look" title="Theme Hybrid's new look">redesigned Theme Hybrid</a> back in April, I&#8217;ve gotten numerous requests for the code so that others could do something similar.</p>
<p>Typically, I&#8217;d point people to the Web Kreation article on <a href="http://web-kreation.com/index.php/wordpress/implement-a-nice-clean-jquery-sliding-panel-in-wordpress-27/" title="Creating a jQuery sliding panel in WordPress">integrating a sliding panel into WordPress</a>.  Unfortunately, this proved to be a tough task for the average end user.  Not to say anything bad about the great tutorial, but there are some problems with integrating it cleanly with WordPress.  Without the ideas generated there, we wouldn&#8217;t have this plugin.</p>
<p>So, I decided to build a sliding panel from the ground up.  I wanted something that would be easy for the average end user to implement.  This plugin is a jQuery-based, fully-widgetized sliding panel for use on your WordPress-powered site.</p>
<h2>What is a sliding panel?</h2>
<p>Quite simply, it is a panel that can be opened and closed with a click of a mouse that will allow you to house additional content on your site without it getting in the way.</p>
<p>Here&#8217;s a view of it in its closed (normal) state:</p>
<div id="attachment_1726" class="wp-caption aligncenter" style="width: 610px"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/06/sliding-panel-closed.png" alt="Sliding panel in its closed state" title="Sliding Panel Closed" width="600" height="208" class="size-full wp-image-1726" /><p class="wp-caption-text">Sliding panel in its closed state</p></div>
<p>Once a reader clicks on the <em>Open</em> button, the panel slides down the page, showing the content of the panel:</p>
<div id="attachment_1727" class="wp-caption aligncenter" style="width: 610px"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/06/sliding-panel-open.png" alt="Sliding panel in its open state" title="Open Sliding Panel" width="600" height="208" class="size-full wp-image-1727" /><p class="wp-caption-text">Sliding panel in its open state</p></div>
<h2>What does the plugin do?</h2>
<p><em>Sliding Panel</em> comes with some neat features:</p>
<ul>
<li>Uses widgets, so you can add any content to the panel you want.</li>
<li>Makes use of the jQuery packaged with WordPress to avoid plugin conflicts.</li>
<li>Auto-inserts itself into a few themes:
<ul>
<li><a href="http://themehybrid.com/themes/hybrid" title="Hybrid WordPress theme framework">Hybrid</a></li>
<li><a href="http://themeshaper.com/thematic" title="Thematic WordPress theme">Thematic</a></li>
<li>Prodigy (not yet released)</li>
</ul>
</li>
<li>Provides the <code>get_sliding_panel()</code> template tag for use in other themes.</li>
</ul>
<h2>Download the plugin</h2>
<p>This plugin will only work with <strong>WordPress 2.8+</strong>.  If you&#8217;re using an older version, you&#8217;ll have to wait until you&#8217;ve updated.</p>
<ul>
<li><strong>Version:</strong> 0.1</li>
<li><strong>Requires:</strong> WordPress 2.8+</li>
<li><strong>Support:</strong> <a href="http://themehybrid.com/support" title="Support forums at Theme Hybrid">Support forums</a></li>
<li><a href="http://wordpress.org/extend/plugins/sliding-panel" title="Download the Sliding Panel plugin from WordPress.org">Download</a> (from WP.org)</li>
</ul>
<p>Instructions on how to use the plugin are in the plugin&#8217;s <code>readme.html</code> file, which is included within the plugin download.</p>
<p class="note">Please don&#8217;t use my contact page or the comments section below to ask support questions.  Use my <a href="http://themehybrid.com/support" title="Theme Hybrid support forums">support forums</a> at Theme Hybrid, which is where I handle all support questions for my WordPress projects.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/Wn_zGYDj0vQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/06/25/sliding-panel-wordpress-plugin/feed</wfw:commentRss>
		<slash:comments>36</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/06/25/sliding-panel-wordpress-plugin</feedburner:origLink></item>
		<item>
		<title>Showing the post password form for excerpts in WordPress</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/AA5KyrecQlk/showing-the-post-password-form-for-excerpts-in-wordpress</link>
		<comments>http://justintadlock.com/archives/2009/06/24/showing-the-post-password-form-for-excerpts-in-wordpress#comments</comments>
		<pubDate>Wed, 24 Jun 2009 08:22:49 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1721</guid>
		<description><![CDATA[How to replace excerpts for password-protected posts in WordPress with a password form instead of the standard no excerpt message.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span> recently came across an interesting situation that I had never thought about before.  Many WordPress themes show excerpts on the front page and other archive-type views.  When viewing a password-protected post, this message is displayed:</p>
<blockquote><p>
There is no excerpt because this is a protected post.
</p></blockquote>
<p>While this is fine for many scenarios, it may not be the most helpful piece of text for the average Internet user.  Instead of showing the message, we&#8217;ll replace it with a password form.</p>
<h2>Replacing the no excerpt text with a password form</h2>
<p>WordPress comes packaged with a neat function called <code>get_the_password_form()</code> that handles most of the work for us.  It generates the entire form.  All we need to do is load it at the appropriate time.</p>
<p>Open your theme&#8217;s <code>functions.php</code> file and drop this code in:</p>
<pre><code>&lt;?php

add_filter( 'the_excerpt', 'excerpt_protected' );

function excerpt_protected( $content ) {
	if ( post_password_required() )
		$content = get_the_password_form();

	return $content;
}

?></code></pre>
<p>This will give us a new message:</p>
<blockquote><p>
This post is password protected. To view it please enter your password below:
</p></blockquote>
<p>Followed by that message is an input field for the post password.</p>
<h2>Writing shorter tutorials</h2>
<p>For those of you that follow this blog regularly, you know that I typically write long, in-depth tutorials.  Many times, these are advanced techniques that not everyone will use.  My plan is to start mixing in some quick tutorials that only take a few minutes to implement and maybe help out the average user more.  This way, I can write more often.  The longer tutorials tend to take a few days of work.</p>
<p>If you have any ideas for WordPress or bbPress tutorials, feel free to let me know in the comments or through my <a href="http://justintadlock.com/contact" title="Contact page">contact form</a>.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/AA5KyrecQlk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/06/24/showing-the-post-password-form-for-excerpts-in-wordpress/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/06/24/showing-the-post-password-form-for-excerpts-in-wordpress</feedburner:origLink></item>
		<item>
		<title>Series: WordPress Plugin</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/jZjDWuXl0NY/series-wordpress-plugin</link>
		<comments>http://justintadlock.com/archives/2009/06/09/series-wordpress-plugin#comments</comments>
		<pubDate>Tue, 09 Jun 2009 08:00:30 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1707</guid>
		<description><![CDATA[A plugin that allows you to tie posts together in a series using the WordPress taxonomy API.  It includes built-in widgets, shortcodes, and template tags.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span>f you follow this blog, you know how much I love the taxonomy system in WordPress.  You especially know how much I love the new automated taxonomy system in version 2.8 of WordPress.</p>
<p>So, it only seems right that I introduce my first taxonomy-based plugin: <em>Series</em>.</p>
<p><em>Series</em> allows you to string together posts by using the built-in taxonomy system in WordPress.  I&#8217;ve packaged several extra goodies with this plugin such as widgets, shortcodes, and template tags to allow you to easily control how display data on your blog.</p>
<p>Right now, the plugin is still in its early stages, but I hope with the help of your ideas and feedback, it&#8217;ll become even greater.</p>
<h2>Features of the Series plugin</h2>
<p><em>Series</em> extends the current taxonomy system by creating a new taxonomy called &#8220;series.&#8221;  Here&#8217;s the current feature list:</p>
<ul>
<li><strong>Series: List Posts widget</strong><br />
	Allows you to lists posts from a specific series and order them how you like.</li>
<li><strong>Series: Related Posts widget</strong><br />
	Lists posts related to the current post on single-post views (not displayed otherwise).</li>
<li><strong>Shortcodes</strong><br />
	Shortcodes to use within the post editor to display series-related things.</li>
<li><strong>Template tags</strong><br />
	Template tags to show things like a series <acronym title="Really Simple Syndication">RSS</acronym> feed and to check whether a post is within a given series (and more, of course).</li>
<li><strong>Automation</strong><br />
	Much of the process is completely automated using WordPress 2.8&#8217;s new taxonomy system.</li>
<li><strong>taxonomy-series.php templates</strong><br />
	Example series archive templates for use with the WordPress Default theme and the <a href="http://themehybrid.com/themes/hybrid" title="Hybrid WordPress theme framework">Hybrid theme</a>.</li>
</ul>
<p>Here&#8217;s a screenshot of the available widgets for use:</p>
<div id="attachment_1708" class="wp-caption aligncenter" style="width: 610px"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/06/series-widgets.png" alt="Screenshot of the Series plugin widgets" title="Series plugin widgets" width="600" height="424" class="size-full wp-image-1708" /><p class="wp-caption-text">Screenshot of the Series plugin widgets</p></div>
<h2>Download the Series plugin</h2>
<p>This plugin will only work with <strong>WordPress 2.8+</strong>.  If you&#8217;re using an older version, you&#8217;ll have to wait until you&#8217;ve updated.  I just wanted to go ahead and get the initial release out.</p>
<p>If you have ideas on how to make this a better plugin, feel free to share them.</p>
<ul>
<li><strong>Version:</strong> 0.1</li>
<li><strong>Requires:</strong> WordPress 2.8+</li>
<li><strong>Support:</strong> <a href="http://themehybrid.com/support" title="Support forums at Theme Hybrid">Support forums</a></li>
<li><a href="http://wordpress.org/extend/plugins/series" title="Download the Series from WordPress.org">Download</a> (from WP.org)</li>
</ul>
<p>Instructions on how to use the plugin are in the plugin&#8217;s <code>readme.html</code> file, which is included within the plugin download.</p>
<p class="note">Please don&#8217;t use my contact page or the comments section below to ask support questions.  Use my <a href="http://themehybrid.com/support" title="Theme Hybrid support forums">support forums</a> at Theme Hybrid, which is where I handle all support questions for my WordPress projects.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/jZjDWuXl0NY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/06/09/series-wordpress-plugin/feed</wfw:commentRss>
		<slash:comments>49</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/06/09/series-wordpress-plugin</feedburner:origLink></item>
		<item>
		<title>Using custom taxonomies to create a movie database</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/SdRW8SzVMpA/using-custom-taxonomies-to-create-a-movie-database</link>
		<comments>http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database#comments</comments>
		<pubDate>Thu, 04 Jun 2009 10:10:29 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1690</guid>
		<description><![CDATA[A tutorial on how I used custom taxonomies in WordPress to build a complete movie database and an explanation of how taxonomies can be used to enhance your site.]]></description>
			<content:encoded><![CDATA[<div id="attachment_1693" class="wp-caption alignright" style="width: 260px"><a href="http://popcritics.com/movies" title="Pop Critics Movies Database"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/06/pop-critics-movies.png" alt="Pop Critics Movie Database" title="Pop Critics Movie Database" width="250" height="479" class="size-full wp-image-1693" /></a><p class="wp-caption-text">Pop Critics Movie Database</p></div>
<p><span class="drop-cap">L</span>ately, I&#8217;ve been writing a lot about how to create custom taxonomies in WordPress.  I still get questions every day about practical applications with them.</p>
<p>Usually, I&#8217;m asked, &#8220;I understand the definition of taxonomy, but what do I do with them?&#8221;  This is what I will attempt to answer in this post.  </p>
<p>At the end of last week, I managed to talk my cousin into helping me set up a <a href="http://popcritics.com/movies" title="Pop Critics Movies Database">movie database</a>.  I thought this would be a great testing ground for custom taxonomies and allow me to present an example of how they can be used.</p>
<p>Go ahead and take a spin around the <a href="http://popcritics.com/movies/" title="Pop Critics Movie Database">database</a> and see what we&#8217;ve put together.  I think it&#8217;s a neat concept.</p>
<p>You should make note that some of the things explained in this tutorial assume that you&#8217;re running WordPress 2.8+.</p>
<p><em>If something in the design is a bit wonky, pay it no attention.  I just quickly merged it with the main site design and it could use some work.</em></p>
<h2>The custom taxonomies</h2>
<p>I created six new taxonomies for my WordPress install: actor, director, genre, producer, studio, and writer.  These taxonomies allow readers to find movies based on certain criteria.  For example, you can view movies that <a href="http://popcritics.com/movies/actors/tom-hanks/" title="Tom Hanks on the Pop Critics movie database">Tom Hanks</a> has starred in.</p>
<p>The idea here is to give readers the ability to navigate around your site.  You want organized content.  You want content that&#8217;s linked together in meaningful ways.  Custom taxonomies allow us to group our content in ways that simple categories and tags can&#8217;t.</p>
<h2>Creating the custom taxonomies</h2>
<p>I recently covered how you can easily <a href="http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28" title="Custom taxonomies in WordPress 2.8">create taxonomies</a> in WordPress 2.8.  To understand the mechanics behind creating and using them, read that post.</p>
<p>To do this, I added this code to my theme&#8217;s <code>functions.php</code> file:</p>
<pre><code>&lt;?php 

add_action( 'init', 'create_pc_db_taxonomies', 0 );

function create_pc_db_taxonomies() {
	register_taxonomy( 'actor', 'post', array( 'hierarchical' => false, 'label' => __('Actors', 'series'), 'query_var' => 'actor', 'rewrite' => array( 'slug' => 'actors' ) ) );
	register_taxonomy( 'director', 'post', array( 'hierarchical' => false, 'label' => __('Directors', 'series'), 'query_var' => 'director', 'rewrite' => array( 'slug' => 'directors' ) ) );
	register_taxonomy( 'genre', 'post', array( 'hierarchical' => false, 'label' => __('Genres', 'series'), 'query_var' => 'genre', 'rewrite' => array( 'slug' => 'genres' ) ) );
	register_taxonomy( 'producer', 'post', array( 'hierarchical' => false, 'label' => __('Producers', 'series'), 'query_var' => 'producer', 'rewrite' => array( 'slug' => 'producers' ) ) );
	register_taxonomy( 'studio', 'post', array( 'hierarchical' => false, 'label' => __('Studios', 'series'), 'query_var' => 'studio', 'rewrite' => array( 'slug' => 'studios' ) ) );
	register_taxonomy( 'writer', 'post', array( 'hierarchical' => false, 'label' => __('Writers', 'series'), 'query_var' => 'writer', 'rewrite' => array( 'slug' => 'writers' ) ) );
}

?&gt;</code></pre>
<h2>Creating term clouds with custom taxonomies</h2>
<p>If you take a look around the movie database, you&#8217;ll notice I&#8217;ve made ample use of term (tag) clouds.  Each represents a different taxonomy and will help you find movies in different ways.</p>
<div id="attachment_1696" class="wp-caption aligncenter" style="width: 610px"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/06/genres.png" alt="A term cloud of movie genres" title="Movie Genres" width="600" height="108" class="size-full wp-image-1696" /><p class="wp-caption-text">A term cloud of movie genres</p></div>
<p>Built into version 0.6 of the <a href="http://themehybrid.com/themes/hybrid" title="Hybrid theme framework">Hybrid theme</a> (will be released after WordPress 2.8) is a widget called <em>Tags</em>.  Traditionally, this widget would allow you to show a tag cloud.  In the new version, there&#8217;s a select box to choose a taxonomy, which allows us to create a term cloud based on any custom taxonomy.  Pretty cool, right?</p>
<p>If you&#8217;re not fortunate enough to be using the <em>Hybrid</em> theme, you can hardcode a term cloud like so:</p>
<pre><code>&lt;?php wp_tag_cloud( array( 'taxonomy' => 'taxonomy_name' ) ); ?&gt;</code></pre>
<h2>Displaying custom taxonomies in a post</h2>
<p>Also covered in my <a href="http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28" title="Custom taxonomies in WordPress 2.8">previous tutorial</a> was how to list taxonomy terms for a post.  Simply replacing <code>taxonomy_name</code> in the below code with the unique name of your taxonomy will handle that.</p>
<pre><code>&lt;?php echo get_the_term_list( $post->ID, 'taxonomy_name', 'Taxonomy Label: ', ', ', '' ); ?&gt;?</code></pre>
<p>Here&#8217;s a look at the movie page (single post view) of <a href="http://popcritics.com/movies/turner-and-hooch/" title="Turner and Hooch">Turner &amp; Hooch</a>:</p>
<div id="attachment_1697" class="wp-caption aligncenter" style="width: 605px"><a href="http://popcritics.com/movies/turner-and-hooch/" title="Turner and Hooch"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/06/turner-and-hooch.jpg" alt="Custom taxonomies on a single-post view" title="Turner and Hooch" width="595" height="415" class="size-full wp-image-1697" /></a><p class="wp-caption-text">Custom taxonomies on a single-post view</p></div>
<p>Notice how each taxonomy&#8217;s terms are listed.  It gives you a view of the actors, genres, directors, producers, studios, and writers for the individual movie.</p>
<h2>Displaying taxonomy terms in a page</h2>
<p>When dealing with the vast amount of movies available, there&#8217;s no good way to show off everything in a sidebar and other  small areas.  I needed a way to show off each taxonomy on a separate page.  So, I created six page templates to handle this:</p>
<ul>
<li><a href="http://popcritics.com/movies/actors" title="Find movies by actor">Actors</a></li>
<li><a href="http://popcritics.com/movies/directors" title="Find movies by director">Directors</a></li>
<li><a href="http://popcritics.com/movies/genres" title="Find movies by genre">Genres</a></li>
<li><a href="http://popcritics.com/movies/producers" title="Find movies by producer">Producers</a></li>
<li><a href="http://popcritics.com/movies/studios" title="Find movies by studio">Studios</a></li>
<li><a href="http://popcritics.com/movies/writers" title="Find movies by writer">Writers</a></li>
</ul>
<p>In each template, I used the <code>wp_tag_cloud()</code> function (shown above) to show off a particular taxonomy.  If you&#8217;re unfamiliar with creating page templates, read this <a href="http://justintadlock.com/archives/2009/03/13/page-templates-the-untapped-potential-of-wordpress" title="Page templates: The untapped potential of WordPress">tutorial on how to create your own</a>.</p>
<h2>Taxonomy term templates</h2>
<p>Taxonomy terms get their own templates just like tags, categories, and other archives.  In keeping with the Tom Hanks scenario, we&#8217;ll take a look at the <a href="http://popcritics.com/movies/actors/tom-hanks/" title="Tom Hanks on Pop Critics">Tom Hanks archive</a>.</p>
<p>There are several things we have to do to make this happen.  First, one useful bit of code I appended to my theme&#8217;s <code>functions.php</code> file allows me to add any <acronym title="Extensible Hypertext Markup Language">XHTML</acronym> to my term descriptions:</p>
<pre><code>remove_filter( 'pre_term_description', 'wp_filter_kses' );</code></pre>
<p>Once that was done, I found <em>Tom Hanks</em> under my <em>Actors</em> taxonomy in my WordPress admin (a sub-menu of <em>Posts</em>).  I then added an image and short description of the actor.  This shows up at the top of the Tom Hanks archive:</p>
<div id="attachment_1698" class="wp-caption aligncenter" style="width: 614px"><a href="http://popcritics.com/movies/actors/tom-hanks/" title="Tom Hanks on Pop Critics"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/06/tom-hanks-archive.jpg" alt="View of the Tom Hanks [actor] archive" title="Tom Hanks taxonomy archive" width="604" height="394" class="size-full wp-image-1698" /></a><p class="wp-caption-text">View of the Tom Hanks actor archive</p></div>
<p>Not all themes&#8217; archives are equipped to handle this.  Instead of hacking up your theme&#8217;s <code>archive.php</code> template, copy and rename it to <code>taxonomy.php</code>.  You&#8217;ll want to add these two code snippets to this file, replacing other code that might be in the way.  <em>Theme authors: You should take note of this.</em></p>
<p>To get the proper name of the taxonomy term (usually the archive page title), use this code:</p>
<pre><code>&lt;?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?&gt;</code></pre>
<p>To show the taxonomy term description, use this code:</p>
<pre><code>&lt;?php echo term_description( '', get_query_var( 'taxonomy' ) ); ?&gt;</code></pre>
<h2>Try creating custom taxonomies for yourself</h2>
<p>I hope this helps explain how taxonomies can be used on a site.  I wanted to give everyone a real-world example to better understand the concept.</p>
<p>I didn&#8217;t go into complete detail on each bit of code because the post was getting much too long.  In order to better understand how the code works, read over my <a href="http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28" title="Custom taxonomies in WordPress 2.8">tutorial on creating custom taxomies</a>.  There&#8217;s a lot of great information in that post.</p>
<p>As always, feel free to ask questions and discuss.  I&#8217;ll be happy to help out.  Heck, go rate a few movies on the movie database.  It could be fun!</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/SdRW8SzVMpA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database/feed</wfw:commentRss>
		<slash:comments>72</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/06/04/using-custom-taxonomies-to-create-a-movie-database</feedburner:origLink></item>
		<item>
		<title>The complete guide to creating widgets in WordPress 2.8</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/6Dih6xe2GlM/the-complete-guide-to-creating-widgets-in-wordpress-28</link>
		<comments>http://justintadlock.com/archives/2009/05/26/the-complete-guide-to-creating-widgets-in-wordpress-28#comments</comments>
		<pubDate>Wed, 27 May 2009 04:04:12 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1646</guid>
		<description><![CDATA[WordPress 2.8 has a new widget class that makes creating widgets much easier. In this tutorial, I'll walk you through a real-world example.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span> have seen some good tutorials on creating widgets for WordPress 2.8 floating around the WordPress-o-Sphere.  But, I didn&#8217;t feel any of them really covered practical usage.  I want to show you how to create a widget for real-world development using WordPress 2.8&#8217;s new widget class.</p>
<p>In this tutorial, I&#8217;ll walk you through the steps of setting up a widget, its settings form, and displaying it on your site.  At the end of the tutorial, you can download an example plugin to build from.  Of course, you can apply this to your themes as well.</p>
<p>If you don&#8217;t feel like reading through the tutorial, skip to the end and download the example widget.  It&#8217;s heavily commented and will give you a good base to build from.</p>
<h2>What will the example widget do?</h2>
<p>For the sake of the tutorial, we&#8217;ll be creating something extremely simple, yet you&#8217;ll see some advanced techniques on how to give users more control over the display of the widget through the widget controls.</p>
<p>Our widget will display a person&#8217;s name and sex.  The controls will allow for the input of a widget title (text input), the input of the user&#8217;s name (text input), the selection of the person&#8217;s sex (select box), and whether the sex should be shown publicly (checkbox).  </p>
<p>Here&#8217;s what the output of the widget will look like:</p>
<p><img src="http://justintadlock.com/blog/wp-content/uploads/2009/05/example-widget.png" alt="Example Widget Display" title="Example Widget Display" width="600" height="151" class="aligncenter size-full wp-image-1647" /></p>
<p>I know, it&#8217;s not much, but you&#8217;ll be able to take these tools and apply them to more complex widgets.</p>
<h2>Loading the widget at the appropriate time</h2>
<p>The first thing we have to do is load our widget when necessary.  WordPress provides the <code>widgets_init</code> action hook that will allow us to do this.  In WordPress 2.8, this action hook is fired right after the default WordPress widgets have been registered.</p>
<pre><code>&lt;?php

/* Add our function to the widgets_init hook. */
add_action( 'widgets_init', 'example_load_widgets' );

/* Function that registers our widget. */
function example_load_widgets() {
	register_widget( 'Example_Widget' );
}</code></pre>
<p>If you wanted to create more than one widget, you&#8217;d use the <code>register_widget()</code> function for each widget inside of the <code>example_load_widgets()</code> function.</p>
<h2>Setting up our widget</h2>
<p>In the past, creating widgets in WordPress was some ugly mish-mash of functions that was incomprehensible.  In 2.8, we simply have to extend the preexisting <code>WP_Widget</code> class.  So, the first step is creating a new class with a unique name.</p>
<pre><code>class Example_Widget extends WP_Widget {</code></pre>
<p>Then, we&#8217;ll want to add our first function.  This function will be what makes our widget unique to WordPress, and it&#8217;ll allow us to set up the widget settings.</p>
<p>Note that the class name and first function name are the same.  In this example this is <code>Example_Widget</code>.</p>
<pre><code>	function Example_Widget() {
		/* Widget settings. */
		$widget_ops = array( 'classname' => 'example', 'description' => 'An example widget that displays a person\'s name and sex.' );

		/* Widget control settings. */
		$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'example-widget' );

		/* Create the widget. */
		$this->WP_Widget( 'example-widget', 'Example Widget', $widget_ops, $control_ops );
	}</code></pre>
<p>You&#8217;ll want to make some of this stuff unique to your widget.</p>
<h2>Displaying the widget</h2>
<p>The next function within our <code>Example_Widget</code> class will handle the display of the widget.  This code might be a little confusing because we don&#8217;t know what it all means (we haven&#8217;t added the controls).</p>
<p>The goal here is to take the settings supplied by what the user selected for the widget and display the widget according to those values.  </p>
<p>It&#8217;s also important to make sure you use the <code>$before_widget</code>, <code>$after_widget</code>, <code>$before_title</code>, and <code>$after_title</code> variables.  These are provided by the theme and should not be hardcoded.  How widgets are displayed should always be handled by the theme.</p>
<pre><code>	function widget( $args, $instance ) {
		extract( $args );

		/* User-selected settings. */
		$title = apply_filters('widget_title', $instance['title'] );
		$name = $instance['name'];
		$sex = $instance['sex'];
		$show_sex = isset( $instance['show_sex'] ) ? $instance['show_sex'] : false;

		/* Before widget (defined by themes). */
		echo $before_widget;

		/* Title of widget (before and after defined by themes). */
		if ( $title )
			echo $before_title . $title . $after_title;

		/* Display name from widget settings. */
		if ( $name )
			echo '&lt;p>Hello.  My name is' . $name . '.&lt;/p>';

		/* Show sex. */
		if ( $show_sex )
			echo '&lt;p>I am a ' . $sex . '.&lt;/p>';

		/* After widget (defined by themes). */
		echo $after_widget;
	}</code></pre>
<h2>Making sure our widget is updated and saved</h2>
<p>In this step, we&#8217;ll take each of our widget settings and save them.  It&#8217;s a pretty simple procedure.  We&#8217;re just updating the widget to use the new user-selected values.</p>
<p>If you&#8217;re using something like a text input in your form and users shouldn&#8217;t add <acronym title="Extensible Hypertext Markup Language">XHTML</acronym> to it, then you should add the value to the <code>strip_tags()</code> function as shown below.</p>
<pre><code>	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		/* Strip tags (if needed) and update the widget settings. */
		$instance['title'] = strip_tags( $new_instance['title'] );
		$instance['name'] = strip_tags( $new_instance['name'] );
		$instance['sex'] = $new_instance['sex'];
		$instance['show_sex'] = $new_instance['show_sex'];

		return $instance;
	}</code></pre>
<h2>Creating widget controls or settings</h2>
<p>The reason the new widget class in WordPress 2.8 is so cool is how easy it is to set up controls for your widgets.  The <code>get_field_id()</code> and <code>get_field_name()</code> functions handle most of the dirty work, leaving us to concentrate on more important things like actually creating the widget.  Take special notice of how these functions are used because it&#8217;ll make life much simpler for you.</p>
<p>First, we might want to set up some defaults.  By setting up defaults, we can control what&#8217;s shown just in case the user doesn&#8217;t select anything.</p>
<pre><code>	function form( $instance ) {

		/* Set up some default widget settings. */
		$defaults = array( 'title' => 'Example', 'name' => 'John Doe', 'sex' => 'male', 'show_sex' => true );
		$instance = wp_parse_args( (array) $instance, $defaults ); ?></code></pre>
<p>The first two parts of the form will be text inputs: the widget title and the person&#8217;s name.</p>
<pre><code>		&lt;p>
			&lt;label for="&lt;?php echo $this->get_field_id( 'title' ); ?>">Title:&lt;/label>
			&lt;input id="&lt;?php echo $this->get_field_id( 'title' ); ?>" name="&lt;?php echo $this->get_field_name( 'title' ); ?>" value="&lt;?php echo $instance['title']; ?>" style="width:100%;" />
		&lt;/p>

		&lt;p>
			&lt;label for="&lt;?php echo $this->get_field_id( 'name' ); ?>">Your Name:&lt;/label>
			&lt;input id="&lt;?php echo $this->get_field_id( 'name' ); ?>" name="&lt;?php echo $this->get_field_name( 'name' ); ?>" value="&lt;?php echo $instance['name']; ?>" style="width:100%;" />
		&lt;/p></code></pre>
<p>The second part of the form will be a select box, allowing the user to select their sex.</p>
<pre><code>		&lt;p>
			&lt;label for="&lt;?php echo $this->get_field_id( 'sex' ); ?>">Sex:&lt;/label>
			&lt;select id="&lt;?php echo $this->get_field_id( 'sex' ); ?>" name="&lt;?php echo $this->get_field_name( 'sex' ); ?>" class="widefat" style="width:100%;">
				&lt;option &lt;?php if ( 'male' == $instance['format'] ) echo 'selected="selected"'; ?>>male&lt;/option>
				&lt;option &lt;?php if ( 'female' == $instance['format'] ) echo 'selected="selected"'; ?>>female&lt;/option>
			&lt;/select>
		&lt;/p></code></pre>
<p>The last part of the form will show a checkbox that allows the user to select whether they want to display their sex publicly.</p>
<pre><code>		&lt;p>
			&lt;input class="checkbox" type="checkbox" &lt;?php checked( $instance['show_sex'], true ); ?> id="&lt;?php echo $this->get_field_id( 'show_sex' ); ?>" name="&lt;?php echo $this->get_field_name( 'show_sex' ); ?>" />
			&lt;label for="&lt;?php echo $this->get_field_id( 'show_sex' ); ?>">Display sex publicly?&lt;/label>
		&lt;/p></code></pre>
<p>The only step left is closing off the form function and the rest of the widget code.</p>
<pre><code>	&lt;?php
	}
}
?></code></pre>
<h2>Time to create your own widgets</h2>
<p>If you&#8217;ve ever created or attempted to create a widget in WordPress prior to 2.8, then you can probably see how much easier this is.  To help people learn the new system, I&#8217;ve put together an example widget.  I&#8217;ve left loads of comments about what code does what in the file, so it should be pretty easy to follow:</p>
<ul>
<li><a href="http://justintadlock.com/downloads/example-widget.zip" title="Example WordPress 2.8 widget">Download the example widget</a></li>
</ul>
<p>I&#8217;m enjoying working with the new widget class.  I almost feel motivated to release a few new widgets in the near future.  But, I&#8217;d love to see what all you come up with.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/6Dih6xe2GlM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/05/26/the-complete-guide-to-creating-widgets-in-wordpress-28/feed</wfw:commentRss>
		<slash:comments>46</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/05/26/the-complete-guide-to-creating-widgets-in-wordpress-28</feedburner:origLink></item>
		<item>
		<title>Customize your 404 page from the WordPress admin</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/yI12qmWszTs/customize-your-404-page-from-the-wordpress-admin</link>
		<comments>http://justintadlock.com/archives/2009/05/13/customize-your-404-page-from-the-wordpress-admin#comments</comments>
		<pubDate>Thu, 14 May 2009 03:35:00 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1676</guid>
		<description><![CDATA[How to easily customize, edit, and update your site's 404 pages in WordPress by widgetizing the 404 template in your theme.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">M</span>ost 404 templates in WordPress themes suck.  They generally read something like &#8220;404 Not Found&#8221; and give an extra sentence or two about an error.  This is totally unnacceptable to a site visitor that comes across a 404 page.</p>
<p>A site&#8217;s 404 page should be unique and reflect what the site owner(s) want.  It&#8217;s tough for theme developers to know how to create a 404 page since they&#8217;re making a theme for thousands of people.  The question becomes: <em>How does one create a 404 template that users can customize from within the WordPress admin?</em></p>
<p>I&#8217;m going to show you an extremely simple technique that&#8217;ll make both theme developers and users&#8217; lives easier.  We will widgetize our 404 templates from this day forward.  </p>
<p>Oh, and by the way, the <a href="http://themehybrid.com/themes/hybrid" title="Hybrid WordPress theme framework">Hybrid theme</a> already uses this method.  Really, did you expect anything less from the coolest theme ever?</p>
<h2>Register your 404 widget area with WordPress</h2>
<p>Like any other widget area, we need to let WordPress know about it.  Open your theme&#8217;s <code>functions.php</code> file and add this <acronym title="Hypertext Preprocessor">PHP</acronym> code in:</p>
<pre><code>&lt;?php
	register_sidebar( array(
		'name' => '404',
		'id' => '404',
		'before_widget' => '&lt;div id="%1$s" class="%2$s widget">',
		'after_widget' => '&lt;/div>',
		'before_title' => '&lt;h3 class="widget-title">',
		'after_title' => '&lt;/h3>'
	) );
?&gt;</code></pre>
<p>If you&#8217;re releasing this theme publicly, you should localize the widget area <code>name</code> but not the <code>id</code>.</p>
<h2>Displaying the widget area on your 404 pages</h2>
<p>Open your theme&#8217;s <code>404.php</code> template and add this to the content area or replace it completely:</p>
<pre><code>&lt;?php dynamic_sidebar( '404' ); ?&gt;</code></pre>
<p>It&#8217;s as simple as that.  Now you can edit your 404 template at any time without having to open your theme files.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/yI12qmWszTs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/05/13/customize-your-404-page-from-the-wordpress-admin/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/05/13/customize-your-404-page-from-the-wordpress-admin</feedburner:origLink></item>
		<item>
		<title>Using shortcodes to show members-only content</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/Vk4rLaLr53k/using-shortcodes-to-show-members-only-content</link>
		<comments>http://justintadlock.com/archives/2009/05/09/using-shortcodes-to-show-members-only-content#comments</comments>
		<pubDate>Sun, 10 May 2009 03:33:34 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1669</guid>
		<description><![CDATA[Simple code snippets for turning your WordPress-powered blog into a powerful members-only site.  Learn how to show content to whoever you want.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span> get several questions every week about setting up a membership site with WordPress.  Although I&#8217;m not going over all the particulars of the process in this post, I want to show you some effective techniques that can make your life much simpler.</p>
<p>This tutorial will cover three methods for setting up shortcodes to use in your posts and pages that will allow you to hide or show content depending on who&#8217;s viewing it.</p>
<h2>Content for users that are not logged in</h2>
<p>Many people want to focus on hiding content from this group of users, but I want to start by showing them content.  Most traffic to your site will likely be through non-logged in users, so make sure you give this group of people something.</p>
<p>Open your theme&#8217;s <code>functions.php</code> file in your favorite text editor.  Add this <acronym title="Hypertext Preprocessor">PHP</acronym> code:</p>
<pre><code>add_shortcode( 'visitor', 'visitor_check_shortcode' );

function visitor_check_shortcode( $atts, $content = null ) {
	 if ( ( !is_user_logged_in() &#038;&#038; !is_null( $content ) ) || is_feed() )
		return $content;
	return '';
}</code></pre>
<p>Anytime you write a post/page, add this to only show content to users that are not logged in:</p>
<pre><code>[visitor]

Some content for the people just browsing your site.

[/visitor]</code></pre>
<p>You should also note that this content will be added to your feeds.  The next two techniques will hide content from feed readers and others on your site.</p>
<h2>Showing content to logged-in users</h2>
<p>Now, you&#8217;ll see how to show content only to users that are logged into your site.  This will be hidden from all other users and not shown in your feeds.</p>
<p>Add this code to your theme&#8217;s <code>functions.php</code> file:</p>
<pre><code>add_shortcode( 'member', 'member_check_shortcode' );

function member_check_shortcode( $atts, $content = null ) {
	 if ( is_user_logged_in() &#038;&#038; !is_null( $content ) &#038;&#038; !is_feed() )
		return $content;
	return '';
}</code></pre>
<p>Then, all you must do is add some content in between your <code>[member]</code> tags when writing a post/page like so:</p>
<pre><code>[member]

This is members-only content.

[/member]</code></pre>
<h2>Showing content depending on user&#8217;s capability</h2>
<p>This bit of code is my favorite because it allows me to check for users based on their capabilities.  You can use something like the <a href="http://www.im-web-gefunden.de/wordpress-plugins/role-manager/" title="Role Manager WordPress plugin">Role Manager</a> plugin to create custom capabilities or just use the default <a href="http://codex.wordpress.org/Roles_and_Capabilities#Capabilities" title="WordPress roles and capabilities">WordPress capabilities</a> to check against.</p>
<p>Add this code to your theme&#8217;s <code>functions.php</code> file:</p>
<pre><code>add_shortcode( 'access', 'access_check_shortcode' );

function access_check_shortcode( $attr, $content = null ) {

	extract( shortcode_atts( array( 'capability' => 'read' ), $attr ) );

	if ( current_user_can( $capability ) &#038;&#038; !is_null( $content ) &#038;&#038; !is_feed() )
		return $content;

	return '';
}</code></pre>
<p>Now, we&#8217;re going to show content only for someone that has the capabilitiy of <code>switch_themes</code> (an administrator in the default WordPress setup):</p>
<pre><code>[access capability="switch_themes"]

The currently logged-in user is a god on this site.

[/access]</code></pre>
<p>The default capability is <code>read</code> in the code above, so adding this will give access to the content to any logged-in user that can read (this is likely everyone):</p>
<pre><code>[access]

You can read, right?

[/access]</code></pre>
<h2>How to show content if user doesn&#8217;t meet requirements</h2>
<p>These shortcodes are great if you just want to hide something.  But, if you want to show a message for people that you&#8217;re hiding content from, you&#8217;ll need to make a small change.</p>
<p>In each of the code snippets above, the line just before the last is:</p>
<pre><code>return '';</code></pre>
<p>That means nothing will be shown if the user doesn&#8217;t meet the requirements defined by the shortcode.  In order to leave them a message, change it to this:</p>
<pre><code>return 'Sorry, but you cannot access this content without...';</code></pre>
<h2>Set up your members-only content</h2>
<p>Of course, this tutorial hasn&#8217;t told you how to get users to sign up.  You&#8217;ll have to figure that out all on your own.  Once they do, you can show whoever whatever content you want.</p>
<p>This is so much nicer than having to use a <acronym title="Hypertext Preprocessor">PHP</acronym> plugin just to check for a user&#8217;s info within a post.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/Vk4rLaLr53k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/05/09/using-shortcodes-to-show-members-only-content/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/05/09/using-shortcodes-to-show-members-only-content</feedburner:origLink></item>
		<item>
		<title>Custom taxonomies in WordPress 2.8</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/_tQZO0rzAR4/custom-taxonomies-in-wordpress-28</link>
		<comments>http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28#comments</comments>
		<pubDate>Wed, 06 May 2009 18:09:17 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1659</guid>
		<description><![CDATA[Why custom taxonomies in WordPress 2.8 are the coolest thing since sliced bread and how you can easily create your own.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span>magine you ran a website that reviewed books, movies, and music.  When writing posts in WordPress, you want to label something as a book, yet you also want to further label it by genre or by author.  </p>
<p>Traditionally, we&#8217;d come up with a way to use our categories and post tags to have some sort of classification system.  I&#8217;m going to show you how you&#8217;ll be able to break free from this rigid system and do things <em>your</em> way.</p>
<p>In WordPress 2.3, the new <a href="http://boren.nu/archives/2007/08/26/wordpress-23-taxonomy-schema/" title="WordPress 2.3 taxonomy schema">taxonomy API</a> was introduced.  It allowed us to make up our own taxonomies.  Here&#8217;s the problem:  <em>No one has been using custom taxonomies.</em></p>
<p>In WordPress 2.8, creating custom taxonomies won&#8217;t even be the job of a plugin developer.  Average users can make and use any taxonomy they want with a few lines of code.  WordPress will handle the rest by adding the meta boxes on the write post page and new admin menus for managing them.</p>
<h2>What is a taxonomy?</h2>
<p>I realize that word may be unfamiliar to many of you.  In short, a taxonomy is a way to group items.  Here&#8217;s the Answers.com <a href="http://www.answers.com/topic/taxonomy" title="Taxonomy">definition of taxonomy</a>:</p>
<ol>
<li>The classification of organisms in an ordered system that indicates natural relationships.</li>
<li>The science, laws, or principles of classification; systematics.</li>
<li>Division into ordered groups or categories.</li>
</ol>
<p>The third definition is probably the best for our purposes.</p>
<p>By default, WordPress comes pre-loaded with three taxonomies: <code>category</code>, <code>post_tag</code>, and <code>link_category</code>.  The first two allow us to label our posts a certain way.  The last lets us categorize our links.  I&#8217;ll be showing you how to easily create your own and use them in this tutorial.</p>
<p>Each taxonomy has what are called <em>terms</em>.  For example, all of your tags are actually <em>terms</em> that live within the <code>post_tag</code> taxonomy.</p>
<h2>What the new taxonomy features do</h2>
<p>Once you&#8217;ve created your new taxonomy, WordPress will set up admin panels for you automatically.  You&#8217;ll also get a new meta box when writing a post.  This is the part that makes the new features in WordPress 2.8 so cool.  We&#8217;re going to be setting up three taxonomies in this tutorial: people, places, and animals.</p>
<p>You&#8217;ll see this when you write a new post:</p>
<p><img src="http://justintadlock.com/blog/wp-content/uploads/2009/05/taxonomies-write-post.png" alt="Custom taxonomies on the WordPress write post screen" title="Custom taxonomies on the WordPress write post screen" width="600" height="393" class="aligncenter size-full wp-image-1655" /></p>
<p>Here&#8217;s the view of the admin panel for our people taxonomy (<em>click image for larger view</em>):</p>
<p><a href="http://justintadlock.com/blog/wp-content/uploads/2009/05/taxonomy-edit-large.png" title="Full view of the edit taxonomy page in WordPress"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/05/edit-taxonomy.png" alt="Edit taxonomy page in WordPress" title="Edit taxonomy page in WordPress" width="600" height="299" class="aligncenter size-full wp-image-1658" /></a></p>
<p>Some of you might have noticed the word &#8220;tags&#8221; in a few places on the page.  I&#8217;m not sure if this will be updated in the future or if it can be easily changed.</p>
<h2>How to create a custom taxonomy</h2>
<p>I&#8217;m only going to cover the basics here for average users.  Plugin developers can take this and do all kinds of neat things.  Also, the new features in WordPress 2.8 only apply to <em>tag-like</em> taxonomies (non-hierarchical) for posts.</p>
<p>In this example, we&#8217;ll be creating three custom taxonomies: people, places, and animals.  You can create as many or as little as you want.</p>
<p>Open your theme&#8217;s <code>functions.php</code> file or create a plugin file to work with.  Add this code:</p>
<pre><code>&lt;?php
add_action( 'init', 'create_my_taxonomies', 0 );

function create_my_taxonomies() {
	register_taxonomy( 'people', 'post', array( 'hierarchical' => false, 'label' => 'People', 'query_var' => true, 'rewrite' => true ) );
	register_taxonomy( 'places', 'post', array( 'hierarchical' => false, 'label' => 'Places', 'query_var' => true, 'rewrite' => true ) );
	register_taxonomy( 'animals', 'post', array( 'hierarchical' => false, 'label' => 'Animals', 'query_var' => true, 'rewrite' => true ) );
}

?&gt;</code></pre>
<h2>Breaking down the code</h2>
<p>Let&#8217;s look at one line of the code we started with and break down each part.  The taxonomy we registered for people looks like this:</p>
<pre><code>register_taxonomy( 'people', 'post', array( 'hierarchical' => false, 'label' => 'People', 'query_var' => true, 'rewrite' => true ) );</code></pre>
<p><code>people</code> tells WordPress what the name of the taxonomy is.</p>
<p><code>post</code> tells WordPress what object type this taxonomy applies to.  You could also make a taxonomy for pages or links if you wanted, but WordPress doesn&#8217;t do the cool stuff with anything but posts right now.</p>
<p><code>hierarchical</code> means whether the taxonomy terms can be in a hierarchy (categories are hierarchical, tags are not).  So, we set this to <code>false</code> to behave like tags and to use the new WordPress features.</p>
<p><code>label</code> is the name of your taxonomy that you want to show up in things like the WordPress admin.  (<em>Note:  This should be localized if you&#8217;re creating a plugin for public release.</em>)</p>
<p><code>query_var</code> lets WordPress know if you want to be able to query posts for things such as showing all posts in the people taxonomy about Will Smith.  If you set it to <code>true</code>, the query variable will be the name of your taxonomy.  This can also be any text string you want.  We&#8217;ll keep ours at <code>true</code> for simplicity.</p>
<p><code>rewrite</code> is whether you want WordPress to give you prettier permalinks when viewing a taxonomy page or archive.  So, you could have something like <code>yoursite.com/people/will-smith</code> rather than <code>yoursite.com/?people=will-smith</code>.</p>
<p>Keep reading, and I&#8217;ll give you some practical usage examples.</p>
<h2>How to create a <em>tag</em> cloud with your custom taxonomies</h2>
<p>Let&#8217;s say you want a <em>people cloud</em> rather than a tag cloud.  Well, we&#8217;d use our standard <a href="http://codex.wordpress.org/Template_Tags/wp_tag_cloud" title="WordPress template tag: wp_tag_cloud()">wp_tag_cloud()</a> template tag with a few extra arguments.  Place this code where you&#8217;d like to show your people cloud:</p>
<pre><code>&lt;?php wp_tag_cloud( array( 'taxonomy' => 'people', 'number' => 45 ) ); ?&gt;</code></pre>
<p>It&#8217;s as simple as that.  All you need to do is set the <code>taxonomy</code> argument to the taxonomy of your choice.</p>
<h2>How to list a taxonomy&#8217;s terms for each post</h2>
<p>Maybe you want to show a particular taxonomy&#8217;s terms along with your post, which is common with categories and tags.  In this example, we&#8217;ll show the terms from the people taxonomy.  Add this within The Loop where you&#8217;d like it to show:</p>
<pre><code>&lt;?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ', '' ); ?&gt;</code></pre>
<h2>How to show posts only from a specific taxonomy</h2>
<p>Let&#8217;s suppose you wanted to create a custom page template or set your home page to show 10 posts with the term &#8220;Will Smith&#8221; (from your people taxonomy).  Add this code before The Loop:</p>
<pre><code>&lt;?php query_posts( array( 'people' => 'will-smith', 'showposts' => 10 ) ); ?&gt;</code></pre>
<p>What?  Did you think it would be tougher than that?</p>
<h2>Create your own custom taxonomies</h2>
<p>Taxonomies are no longer something that only plugin developers can create.  It&#8217;s time for you to go out and explore custom taxonomies for yourself.  Make something that is unique to your site.</p>
<p>I&#8217;m thinking of making a <em>WordPress</em> taxonomy for my blog since that&#8217;s pretty much all I blog about.</p>
<p>If you have questions or would like to see more practical usage examples, feel free to ask in the comments.  It might even be cool to set up a big list of ideas for new taxonomies.  There&#8217;s so much more we could do that I couldn&#8217;t cover in one tutorial.  It might be worth writing another one if everyone feels we need it.</p>
<p class="note">Remember, this tutorial is for WordPress 2.8, which is under development at the time of writing.  Things could change by the time it&#8217;s released.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/_tQZO0rzAR4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28/feed</wfw:commentRss>
		<slash:comments>124</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28</feedburner:origLink></item>
		<item>
		<title>How to create a forums list in bbPress</title>
		<link>http://feedproxy.google.com/~r/JustinTadlock/~3/ek9Vhp-kWp4/how-to-create-a-forums-list-in-bbpress</link>
		<comments>http://justintadlock.com/archives/2009/05/03/how-to-create-a-forums-list-in-bbpress#comments</comments>
		<pubDate>Sun, 03 May 2009 23:40:58 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[bbPress]]></category>
		<category><![CDATA[bbPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1639</guid>
		<description><![CDATA[How to create a list of your forums for bbPress with a link to each forum, its <acronym title="Really Simple Syndication">RSS</acronym> feed, and number of posts.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">W</span>hile redesigning the Theme Hybrid <a href="http://themehybrid.com/support" title="Theme Hybrid support forums">support</a> and <a href="http://themehybrid.com/community" title="Theme Hybrid community forums">community</a> forums, I needed an easy way to show off the list of forums with links to the <acronym title="Really Simple Syndication">RSS</acronym> feeds and number of posts next to each forum name.  </p>
<p>What I&#8217;ll be showing you in this tutorial is a simple way to do this.</p>
<p>I prefer to have the list of forums in the sidebar while showing the most recent posts in the content area.  But, you can use this code in any of your template files for use anywhere on your forums.</p>
<h2>The code</h2>
<p>What we&#8217;ll be doing is using the <code>get_forums()</code> function to grab an array of all of your forums.  Then, we&#8217;ll loop through the array, listing a link to each forum, showing the number of posts, and linking to the <acronym title="Really Simple Syndication">RSS</acronym> feed.</p>
<pre><code>&lt;div class="forums-list"&gt;

	&lt;h3&gt;Forums&lt;/h3&gt;

	&lt;ul&gt;

	&lt;?php $forums = get_forums(); ?&gt;
	&lt;?php foreach ( $forums as $forum ) : ?&gt;

		&lt;li&gt;
			&lt;a class="forum-link" href="&lt;?php forum_link( $forum-&gt;forum_id ); ?&gt;"&gt;&lt;?php forum_name( $forum-&gt;forum_id ); ?&gt;&lt;/a&gt;
			&lt;span class="forum-posts"&gt;(&lt;?php forum_posts( $forum-&gt;forum_id ); ?&gt; posts)&lt;/span&gt;
			&lt;a class="rss-link" href="&lt;?php bb_forum_posts_rss_link( $forum-&gt;forum_id ); ?&gt;"&gt;(&lt;abbr title="Really Simple Syndication"&gt;RSS&lt;/abbr&gt;)&lt;/a&gt;
		&lt;/li&gt;

	&lt;?php endforeach; ?&gt;

	&lt;/ul&gt;

&lt;/div&gt;</code></pre>
<h2>The finished product</h2>
<p>I worked a little extra <acronym title="Cascading Style Sheets">CSS</acronym> magic on mine and came up with this:</p>
<p><img src="http://justintadlock.com/blog/wp-content/uploads/2009/05/bbpress-forums-list.png" alt="bbPress Forums List" title="bbPress Forums List" width="600" height="343" class="aligncenter size-full wp-image-1640" /></p>
<p>I hope you have fun with this code and come up with more unique ways to show off your forums.  I provided a few <acronym title="Cascading Style Sheets">CSS</acronym> classes to help you out if you want to add your own style.  Here they are for reference:</p>
<pre><code>/* Containing &lt;div&gt; */
.forums-list {}

/* Header */
.forums-list h3 {}

/* List */
.forums-list ul {}
.forums-list li {}

/* Forum link */
a.forum-link {}

/* Number of forum posts */
span.forum-posts {}

/* Forum RSS Link */
a.rss-link {}</code></pre>
<h2>More bbPress tutorials and discussion to come</h2>
<p>I&#8217;m not really sure how many folks are using <a href="http://bbpress.org" title="bbPress forum software">bbPress</a> these days, but it&#8217;s the forum software of choice for me.  It&#8217;s simple and lightweight &mdash; everything I need in forum software.  I hope that I can bring more people to this platform and do my part in helping the bbPress community grow.</p>
<p>I also hope to continue writing more tutorials like this one, so there&#8217;ll be more documentation out there.  If you have ideas for tutorials, I&#8217;ll see if I can squeeze them in sometime.</p>
<img src="http://feeds.feedburner.com/~r/JustinTadlock/~4/ek9Vhp-kWp4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/05/03/how-to-create-a-forums-list-in-bbpress/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://justintadlock.com/archives/2009/05/03/how-to-create-a-forums-list-in-bbpress</feedburner:origLink></item>
	</channel>
</rss>
