How to organize your content with WordPress custom taxonomies

11 Comments

Organizing content can be a lot of fun. Well, it can be a lot of fun if you’re a crazy blogger/librarian-at-heart, like many of us are. When you have a good deal of content it can quickly become more than you can handle, if you don’t have a decent system in place. I would even argue that unless you have a handle on your content, no one else can be expected to either.

Well organized content could just make the difference between someone browsing your site or leaving right away.

In this tutorial I’ll give my own recommendations on how to organize your content first, and then how to actually create any necessary taxonomies for your organizational system.

How to organize your blog content

Organizing is a funny thing. Getting organized first, and early, is the best way to stay organized, but you need a solid sampling of content to really get a system together. I would say to have enough organize you should have around 100 posts. So, write those 100 posts first.

Go ahead, I’ll wait here.

In all seriousness, you will need something to work with. Every blog will need a different number of posts, but the principal stands. In any case, when you have your initial content, you can start grouping.

Group together posts that are related, with a focus on larger groupings over smaller ones. Find relationships between posts that could help your readers. Avoid groupings of two, since that won’t give your readers much to look at.

I could look at the posts on WPCandy, and notice a few groupings: posts about Matt Mullenweg, posts covering WordPress news, posts focused on the Portland area, and posts about WordCamp, for example. These are all great groupings because they are relevant, straightforward, and they collect a number of posts. Next, let’s turn the various groups into taxonomies.

  • Posts about Matt Mullenweg = People
  • News report posts = Categories, or Content Types
  • Posts focused on the Portland area = Locations
  • Posts about WordCamp = Topics, or Tags

There are other ways posts could be classified, too: companies, events, series (for sequential, tightly related posts), audience, and skill level are all possible ways of classifying and organizing your content. We use most of these at WPCandy. Depending on your content you may have some very unique potential taxonomies on your hands.

You can see an example of many of our taxonomies in our 2010 year in review post. Also, if you really get into this kind of taxonomy geekery, read this great piece by Stijn Debrouwere called “Tags don’t cut it”.

Now that you have your taxonomies in place conceptually, let’s build them out for your WordPress site. For that, we’ll use WordPress custom taxonomies, introduced to the platform in version 3.0.

Creating custom taxonomies

We’re going to walk through creating one custom taxonomy. You can then lather, rinse, and recode as necessary for as many systems as you need.

The PHP for adding a custom taxonomy looks like this:

function people_init() {
  register_taxonomy(
    'people',
    'post',
    array(
      'label' => __('People'),
      'rewrite' => array('slug' => 'profiles'),
    )
  );
}
add_action( 'init', 'people_init' );

In this case we’re adding a “people” taxonomy, that will allow us to tag our posts with the individuals that are mentioned in it. Now let’s break that down, line by line.

function people_init() {
  register_taxonomy(

Okay, we’ll start with two lines, but they’re pretty basic. The first line starts the function, and the second cues register_taxonomy, which is the function that creates our taxonomy.

    'people',

The third line is the internal name for the taxonomy, or what it will be called inside WordPress, in the database, and in your theme.

    'post',

This line denotes which of the content on your WordPress site will be classified by this taxonomy. Here we’re choosing posts, but we could also choose pages or links (or a custom post type).

      'label' => __('People'),

This is how the taxonomy is described within the WordPress Dashboard, and on the meta box on the post screen where you classify your post.

      'rewrite' => array('slug' => 'profiles'),

This line sets the slug for your taxonomy. So for this taxonomy the URLs would read sitename.com/profiles/namehere. Choose your slugs carefully, so that you don’t run into any conflicts with pages or other content down the road.

add_action( 'init', 'people_init' );

This simply adds the taxonomy to your site.

And there you have it! Just to drive the point home, this is what it would look like if we were creating a location taxonomy.

function locations_init() {
  register_taxonomy(
    'locations',
    'post',
    array(
      'label' => __('Locations'),
      'rewrite' => array('slug' => 'in'),
    )
  );
}
add_action( 'init', 'locations_init' );

You can, and should, refer to the WordPress Codex for more information on the parameters register_taxonomy supports.

Good for more than just your functions.php

One last recommendation regarding these custom taxonomies: don’t leave the PHP for your custom taxonomies in your WordPress theme’s functions.php file. If you do, you might forget it’s there and change your theme later without moving the relevant functions. I would recommend creating a functionality plugin, just for your site, and keep code like this in there. I’ll talk more about the idea of a functionality plugin soon.

Do you use many taxonomies to organize your content? Are you doing anything particularly unique?

11 thoughts on “How to organize your content with WordPress custom taxonomies

  1. Nice to see another little insight into what goes on at WPCandy.com in and around the Custom Taxonomies area, and I love what you have done with them (I feel like I’m repeating myself in places?)

    But I agree, Custom Taxonomies are a grand way to separate your content!

  2. Quick question, does passing the second arg (object_type) as a string (rather than an array) make the taxonomy non-hierarchical? The docs aren’t very clear on this.

    Thanks for the good example.

  3. One of the more useful things that I found to do with taxonomies is to create things on my site that you might find in a book. For example there’s an index as well as a glossary. My only gripe is that I do not generate enough content to make these structures as useful as they were intended to be 🙂

    • Would this be a correct interpretation of Michael’s structure?… The taxonomy ‘topics’ has a description field that serves as the definition in the glossary. The glossary page is a list of the taxonomy terms. The topics pages are a taxonomy template, with the description/definition field appears at the top, before the ‘loop’ of terms (not a capital-L loop, but a for-each loop)

      I have a CMS use case where I’d like to attribute a Post to a person, but not using the formal WordPress User/Author structure. Perhaps a taxonomy of Contributor, with the fields ‘bio’, ‘logo’ , ‘website’ etc.
      would mimic Michael’s Glossary and Topics.
      Sorry…thinking out loud…of course that should work. It would be the same as Ryan’s “Person” taxomony example only a shift of perspective. Instead of a post taxed about a person, it’s a post taxed contributed by a person.

      • @JA Almost… The glossary page is a WordPress page with a custom shortcode that spits of all terms of a given taxonomy that have descriptions. The Index page is also a page that does the same, but with all terms having associated objects. The topic pages are normal WordPress term archives and the loop is actually “The Loop” which cycles all objects associated with a given topic. I say object because WordPress does not restrict term archives to the “post” post_type. On the archive page for the topic taxonomy, you will see posts, pages as well as custom post_type “mfields_bookmark”.

  4. How can I delete taxonomies I’ve added from the admin panel? I see and add taxonomy button but not a delete one.

  5. Pingback: Note 183 – Well organised blog content « My writing challenge

Comments are closed.