5 min read

What and Why?

Taxonomy is described as the science of classification. In terms of how it applies to Drupal, it is the method by which content is organized using several distinct types of relationship between terms. Simple as that! This doesn’t really encompass how useful it is, though, but before we move on to that, there is a bit of terminology to pick up first:

  • Term: A term used to describe content (also known as a descriptor)
  • Vocabulary: A grouping of related terms
  • Thesaurus: A categorization of content that describes is similar to relationships
  • Taxonomy: A categorization of content into a hierarchical structure
  • Tagging: The process of associating a term (descriptor) with content
  • Synonym: Can be thought of as another word for the current term.

It may help to view the following diagram in order to properly grasp how these terms inter-relate.

Building Powerful and Robust Websites with Drupal 6

This serves to illustrate the fact that there are two main types of vocabulary. Each type consists of a set of terms, but the relationships between them are different in that a taxonomy deals with a hierarchy of information, and a thesaurus deals with relationships between terms. The terms (shown as small boxes) and their relationships (shown as arrows) play a critical role in how content is organized.

One of the things that makes the Drupal taxonomy system so powerful, is that it allows content to be categorized on the fly (as and when it is created). This unburdens administrators because it is no longer necessary to moderate every bit of content coming into the site in order to put it into pre-determined categories. We’ll discuss these methods in some detail in the coming sections, but it’s also worth noting quickly that it is possible to tag a given node more than once. This means that content can belong to several vocabularies, at once. This is very useful for cross-referencing purposes because it highlights relationships between terms or vocabularies through the actual nodes.

Implementing Controlled Taxonomies in Drupal

The best way to talk about how to implement some form of categorization is to see it in action. There are quite a few settings to work with and consider in order to get things up and running. Let’s assume that the demo site has enlisted a large number of specialists who will maintain their own blogs on the website so that interested parties can keep tabs on what’s news according to the people in the know.

Now, some people will be happy with visiting their blog of choice and reading over any new postings there. Some people, however, might want to be able to search for specific topics in order to see if there are correlations or disagreements between bloggers on certain subjects. As there is going to be a lot of content posted once the site has been up and running for a few months, we need some way to ensure that specific topics are easy to find, regardless of who has been discussing them on their blogs.

Introduction to Vocabularies

Let’s quickly discuss how vocabularies are dealt with in the administration tool in order to work out how to go about making sure this requirement is satisfied. If you click on the Taxonomy link under Content management, you will be presented with a page listing the current vocabularies. Assuming you have created a forum before, you should have something like this:

Building Powerful and Robust Websites with Drupal 6

Before we look at editing terms and vocabularies, let’s take a look at how to create a vocabulary for ourselves. Click on the add vocabulary tab to bring up the following page that we can use to create a vocabulary, manually:

Building Powerful and Robust Websites with Drupal 6

By way of example, this vocabulary will deal with the topic of hunting. This vocabulary only applies to blog entries because that is the only content (or node) type for which it is enabled—you can select as many or as few as you like, depending on how many content types it should apply to.

Looking further down the page, there are several other options that we will discuss in more detail, shortly. Clicking on Submit adds this vocabulary to the list, so that the main page now looks like this:

Building Powerful and Robust Websites with Drupal 6

So far so good, but this will not be of much use to us as it stands! We need to add some terms (descriptors) in order to allow tagging to commence.

Dealing with Terms

Click on add terms link for the Hunting vocabulary to bring up the following page:

Building Powerful and Robust Websites with Drupal 6

The term Trapping has been added here, with a brief description of the term itself. We could, if we choose, associate the term Poaching with Trapping by making it a related term or synonym (of course, you would need to create this term first in order to make it a related term). Click on the Advanced options link to expose the additional features, as shown here:

Building Powerful and Robust Websites with Drupal 6

In this case, the term Trapping is specified as being related to Poaching and by way of example, gin traps is a synonym. Synonyms don’t actually do anything useful at the moment, so don’t pay too much mind to them yet, but there are modules that expose additional functionality based on related terms and synonyms, such as the Similar by Terms module.

The Parents option at the start of the Advanced options warrants a closer inspection, but as it relates more closely to the structure of hierarchies, we’ll look at it in the section on Hierarchies that’s coming up.

For now, add a few more terms to this vocabulary so that the list looks something like this:

Building Powerful and Robust Websites with Drupal 6

It’s now time to make use of these terms by posting some blog content.

Posting Content with Categories Enabled

Using any account with the requisite permissions to add blog content, attempt to post to the site. You should now be able to view the newly inserted Hunting category, as shown here:

Building Powerful and Robust Websites with Drupal 6

Now comes the clever bit! Once this blog node has been posted, users can view the blog as normal, except that it now has its term displayed along with the post (bottom right):

Building Powerful and Robust Websites with Drupal 6

Where does the descriptor link take us? Click on the term, in this case Canned hunting, and you will be taken to a page listing all of the content that has been tagged with this term. This should really have you quite excited, because with very little work, users can now find focused content without having to look that hard—this is what content management is all about!

Subscribe to the weekly Packt Hub newsletter. We'll send you the results of our AI Now Survey, featuring data and insights from across the tech landscape.

* indicates required


Please enter your comment!
Please enter your name here