In this lesson we're going to talk about taxonomy. In my experience it's another one of those things in Drupal that uses unfortunate terminology and ends up confusing new users. But the truth is, taxonomy is pretty simple to get your head around and will be a huge help in your site building efforts.
The Lowdown on this Tutorial
We're going to break this topic down by first explaining the concepts. Next we'll take a brief tour of where Drupal keeps all the knobs and switches for managing taxonomy and then we'll wrap it up by discussing some very useful modules that extend the built-in functionality of the Taxonomy module.
If you've been keeping up with this tutorial series, you'll know it uses my free installation profile, Foundation, for the examples. Using Foundation along with the lessons can save some time in getting up to speed on this topic. It includes several pre-configured modules and views related to the topic of taxonomy that serve as good examples of how it can help with your site building.
Let's begin by defining taxonomy. You may remember it from your high school biology class as a systematic way of categorizing things. In biology, the classifications involve plants and animals, but in Drupal the categories are for your content.
If you're coming from WordPress, this system is very similar to the Categories you'll find in that CMS. In Drupal, however, it's a little more complex - big surprise, right? That's OK. Like I said, it's not that bad.
To really understand Drupal's taxonomy or classification system, we have to get a handle on both vocabularies and terms. Vocabularies are really just categories. That's all they are. Terms are simply the items that go inside a vocabulary. Let's look a little deeper at terms and vocabularies using an example.
A Hypothetical Vocabulary
By default, Drupal comes with one vocabulary defined - Tags. It's a generic, default way to start classifying your content. But let's say we have a site that provides information about the nutritional content of various foods. We'll probably want to create a new vocabulary (aka category) that we'll call Foods.
Under that vocabulary we'll start adding some terms to break our content down into more specific classifications - terms like Dairy, Grains, Poultry, Vegetables and Fruits. As you might guess, these will end up being not only terms themselves, but also the headings for sub-categories as we continue drilling down to more specific terms. For example, under Fruits we might have Apples, Bananas, etc. You can see that it won't take long before we have a very extensive hierarchy with hundreds, or even thousands, of terms.
Of course the point of all this categorization is to make it easier to sort our content and expose how each node is related to the others. If you think back to the previous lessons on Views, you'll start seeing how these two modules - Taxonomy and Views - work hand-in-glove to provide a way of creating and displaying content relationships in a relatively simple way.
How to Use Taxonomy
Let's kick this section off by looking at where we create and manage our vocabularies and terms. In Drupal 7, under Structure > Taxonomy you'll find a screen like the one below.
You'll see that in this screenshot from Foundation, we have two vocabularies, the default Tags, which I've chosen to use as the blog categories, and a second titled, Utility tags. This second vocabulary/category is used to mark content as special in some way - for example, to be featured on the home page.
I won't go through the steps of creating vocabularies or terms because it's very simple and I'm certain you can handle that without much trouble. But what we are going to look at is how we can make our new vocabularies available for use when creating content. You see, when you create a new vocabulary, it isn't automatically available on your Add content form. We have to add it manually.
To do this, we'll need to add a field to the content types where we want to be able to use the vocabulary. If you're using Foundation, head to Structure > Content Types and then select Manage fields under the Article content type. You'll see something similar to the image below.
Note the big red arrow. What you see is that I've added a field to my content type. It's a term reference and it associates the vocabulary Utility tags with the content type. In this case it allows me to tag an article as one that should be added to the home page (via a view).
But if we return to the example of a Foods vocabulary, this is where we could add it as well. We would simply add a new field and under field type, select Term reference and then set the desired widget (select list, checkboxes, etc.). After we click save, we'll be prompted for the vocabulary name and some default settings for the field.
After we've done this, we'll be able to tag our content with the terms we've defined when we're creating or editing the page. It's pretty simple, but if you want your users to be able to see the vocabulary terms on the page (so they might click them to view related content), we're not quite finished.
Go back to Structure > Content Types and then select Manage display under the Article content type. You'll see something similar to the image below.
You'll notice that in this case we have our Utility tags hidden from our site's visitors. But in the case of our hypothetical Foods vocabulary, we'd want to make sure it was displaying so that our site's visitors could use it to find and perhaps sort related content.
If this was what we wanted to do, I would also recommend enabling the Taxonomy term view (included by default with Views) and customizing the display of the pages that site visitors will see when they click on a taxonomy term. It would be in this view where you might expose a dropdown to your users that would let them easily sort through the content associated with the various terms you've defined.
That wasn't so bad, was it? It won't be long before you'll want to do all sorts of things with taxonomy and below are a few modules that will help.
This module will allow you to turn your vocabularies into menus. In my experience, the module works great so long as you don't try to disable any menu items. I've always had disabled items get re-added after cron runs, but otherwise no problems.
You know those tag clouds you've seen on some sites? This module is one way you can do that with Drupal.
In the example we used in this tutorial, we saw how quickly you can create a deep vocabulary structure. The Taxonomy Breadcrumb module is a useful way of helping your users keep track of where they are.
Finally I'll leave you with the full list of taxonomy related modules - only 372 of them for you to sort through! Gotta love Drupal, huh?
That's it for this lesson. We're a bit more than a fifth of the way through this series. Stay up to date via the series RSS feed or by subscribing to email updates for the blog. If you'd like to comment on anything in this lesson, you can do so on this discussion thread.