Taxonomies

What is a taxonomy?

Rating A taxonomy is a way of classifying things. For example, in the US, movies are rated as G, PG, PG-13, R, or NC-17. Classifying movies helps people make decisions about what they want to see.

Some taxonomies are closed, that is, the number of items is fixed, and rarely, if ever, changes. The movie ratings are like that. The categories haven’t changed in years.

Other taxonomies are open, meaning that new categories are added from time to time. Take Amazon, for example. Here’s a list of product categories:

Amazon

As new products are added, Amazon might add new categories. For example, Amazon might start selling real estate. That’s not in their existing taxonomy. They’d add an item for it.

Another place you see open taxonomies is in keyword lists on Web sites. For example, Medium.Com lets people write and publish articles. Authors get to mark their articles with keywords.

Medium

Authors type in the keywords that are most relevant to their stories. Keywords help readers find stories they’re interested in. Readers can even subscribe to keywords. They’re notified when stories with their keywords are published.

Adela
Adela
I was using a Web site, and they had the keywords “horse” and “horses.” Why have both? Is it because one author use horse as a keyword, and another used horses?
Ruben
Ruben
Right! That’s a problem with open taxonomies. Every so often, someone should go through the keywords, find keywords that are close, and merge the categories. Sometimes authors misspell keywords, too.
Georgina
Georgina
When were looking at field types, we had a “List (text)” field.

List of text

That looks like a taxonomy.
Ruben
Ruben
Good thinking! When you have categories, you can use a List (text) field instead of a taxonomy. A couple of differences.

First, if the list keeps changing, you would have to keep going back and changing the field. A nuisance. On the other hand, if you have a taxonomy and a user types in a new term, Drupal can automatically add the term to the taxonomy.

Second, when you make a taxonomy, Drupal automatically creates a page for each term. For example, if you have a real estate taxonomy, and five listings have the term “condo,” Drupal creates a page with the title Condo, and lists the five nodes that have that term.

So, choose whatever works best for your IS.

Creating a taxonomy

Say we’re running a computer gaming site, with pages about different games. Let’s create a taxonomy for computer game genre. There are different ways to classify games, so let’s leave it up to page authors to come up with the terms.

Structure | Taxonomy, then Add taxonomy.

New taxonomy

Then let’s add a few terms:

Terms

Now let’s make a content type called Game. To give nodes terms from the Game genres taxonomy, we add a reference field to the content type. It references terms in the taxonomy.

Add field

Make it multivalued, so that page authors can give games as many terms as they like:

Multivalued

Some more options to set:

Options

Look at the last check box. If an author types a new term, Drupal will add it to the taxonomy.

Let’s see what happens when someone enters a new game. I chose a special input widget called “Autocomplete (Tags style)” that’s specially designed for use with taxonomies.

Widget

Here’s the input form:

New game

I’ll type in the name of a game, and start typing a term:

Existing term

There’s a term beginning with F in the taxonomy, so Drupal shows it. If there was more than one beginning with F, it would show them all. This is called autocomplete.

I’ll finish with a term that isn’t in the taxonomy:

New term

I save the new game node. Then I check out the list of terms in the Game genre taxonomy:

Terms

The new term is in the taxonomy. Hooray!

When I create another game node, the new term is part of the autocomplete:

Another game

If I look at the new node, the terms are listed:

New node

By default, Drupal makes the terms into links. Click on a link, and I can see all the nodes with that term:

Nodes with term

Exercise

Exercise: Hobbies taxonomy
You should have martian and sloth content types in the same Drupal (contenttypes or whatevs). If you don’t, make it so.

Add a taxonomy called Hobbies to the site. Add some terms, like Sleeping, Throwing feces, Disturbing the peace, whatever you like.

Add multivalued reference fields to the martian and sloth content types, referencing the new taxonomy. Use the autocomplete (tags style) form widget.

Submit the URL of your site, and login credentials for user 1.

(If you were logged in as a student, you could submit an exercise solution, and get some feedback.)

Summary

A taxonomy is a way of classifying things. Drupal automatically creates a page for each term. To give nodes terms from a taxonomy, add a reference field. There’s a special input widget called “Autocomplete (Tags style)” that’s specially designed for use with taxonomies.