Drupal Taxonomy Part 1

A look at Taxonomy — the feature used to sort articles.

Taxonomy is used to sort articles by category and tag. Drupal's Taxonomy feature doesn't fix it to a category or tag use case — you adapt how you use it to your purpose, whether that's category-style or tag-style.

The concept is to give each article multiple arbitrary labels, then find articles by those labels. Think of Taxonomy as the feature that lets you freely create those labels, and it starts to make sense.

Drupal's Taxonomy

To use Taxonomy in Drupal:

  1. Create a vocabulary as the parent genre.
  2. Create terms within that vocabulary as child genres.

Taking my site as an example:

  1. Create a vocabulary called Article category
  2. Create a term called Drupal Article within Article category
  3. Create a term called Web Article within Article category
  4. Create a term called Mac Article within Article category
  5. Create a term called AWS Article within Article category

Clicking Drupal Article in the menu then shows a list of all Drupal articles.

Since this is the foundation of article sorting, I'll cover the basic usage and concept.

In this article, I'll put together an overview of Drupal's Taxonomy feature.

1. Taxonomy Overview

Drupal's Taxonomy feature is simple yet highly flexible, making it usable in a wide variety of ways. The most basic use is as a feature for sorting articles by category.

If you've used WordPress, you'll have seen categories and tags. Both are features for sorting articles — let's think about their respective purposes.

1-1. Categories

Categories broadly sort articles into genres, assign them to menus, and let readers find articles by browsing the genre structure in those menus. Categories have a hierarchy — here's an example of how that might work.

For a site featuring restaurant articles:

Category usage example — categorizing restaurants

|-- Restaurants
|     |
|     |-- Western food
|     |    |-- Hamburg steak
|     |    |-- Steak
|     |    |-- Bistro
|     |    |-- Omurice
|     |
|     |-- Chinese food
|     |    |-- Casual Chinese
|     |    |-- Chinese set meals
|     |    |-- Sichuan cuisine
|     |    |-- Cantonese cuisine

The category structure runs three levels deep: Restaurants > Western food > Hamburg steak.

The actual article covers Hamburg steak specifically, which belongs under Western food, which belongs under Restaurants. The reason for this hierarchy: if you threw Hamburg steak and Sichuan cuisine together without any structure, readers would struggle to find the article they're looking for.

Giving readers a clear path to find content — Restaurants > Western food > Hamburg steak, a structure most people would naturally associate with that content — and surfacing it through menus is what categories do.

Categories have hierarchy; the site operator defines the hierarchy; readers use those paths to navigate.

1-2. Tags

Tags work differently from categories. You don't need to set them up in advance — you add new tags as needed each time you create an article. Readers find articles through tags by browsing a tag cloud where all tags are listed, clicking whatever interests them. Unlike categories, tags carry no hierarchy concept since keywords can be set freely.

Using tags for the same restaurant articles might look like this:

Tag usage example — restaurant-related tags

|-- Restaurants

|-- Western food
|
|-- Hamburg steak
|-- Steak
|-- Bistro
|-- Omurice
|
|-- Casual Chinese
|-- Sichuan cuisine
|-- Cantonese cuisine

The value of tags is that more detailed information can be offered at a granular level, making articles easier to find that readers might otherwise miss. The problem is that without any hierarchy, tags can multiply unnecessarily, and readers end up unable to find what they're looking for — the opposite of the intended effect.

1-3. Drupal's Taxonomy Feature

Drupal's Taxonomy doesn't come with a fixed concept of categories or tags — you can use it as categories or as tags depending on your purpose.

In WordPress, it would be: Tag > Hamburg steak, Category = Restaurants > Western food > Hamburg steak.

In Drupal, the basic concept is vocabulary > term, so:

Restaurants = vocabulary > Western food = parent term > Hamburg steak = child term — and you can build hierarchy from there.

The result is the same as WordPress categories, but WordPress categories can only be displayed in the way they're configured. Drupal also requires configuration, but you can separately set it up as Western food > Hamburg steak, or use it tag-style with Hamburg steak, Steak, and Bistro listed side by side.

Categories are fundamentally designed to be used as menus, with hierarchy fixed accordingly. WordPress generally doesn't accommodate changing the menu items per page very easily — it's possible, but involves considerable effort. Drupal has the Block layout feature, which makes it straightforward to change the menu on a per-article basis.

Setting this aside since this article is about Taxonomy — in the Views feature, Taxonomy elements can be used as extraction conditions, and filtering further by term enables quite detailed categorization, making it easy to create organized pages tailored to specific purposes.

As noted at the start: Drupal's Taxonomy is about attaching multiple labels to an article, then freely calling up and using articles by those labels. This goes beyond the typical category or tag use case and enables freely organizing, retrieving, and displaying articles in any form.

Beyond taxonomy, URL aliases can also be set per article — and applying consistent rules to those aliases enables sorting by alias as well.

Straying a bit from the Taxonomy article, but one of the interesting things about Drupal is that combining multiple features lets you use a single article's information in a wide variety of ways. As I'll cover later, taxonomy on its own generates a list page — but combined with other elements, what was one use case for standalone taxonomy becomes multiple use cases when combined with Views, and even more when Block layout and aliases are added to the mix.

2. How to Use Taxonomy

The basics of Taxonomy were covered in the article #C15 Using Content and Structure., but I'll go through it again here.

To use Taxonomy for the first time:

  1. Create a vocabulary
  2. Create terms within the vocabulary 

Those two steps are required.

The two taxonomies configured in the #L02 Lee 101Z 50's article from #C15 Using Content and Structure. are:

  1. Tags: Life Style | Tags = vocabulary / Life Style = term
  2. Article category: Old-Clothes Article. | Article category = vocabulary / Old-Clothes Article. = term

2-1. Broad Classification

Named "Tags," though the name itself doesn't have to be "Tags." The terms configured within this vocabulary are:

  1. Creation
  2. Life Style

Just two terms, but they serve an important role: to determine which of the site's two themes an article belongs to. They're configured to drive the list for each theme and to display new arrivals on the top page. Creating a new article and assigning one of the terms means that once published, the article automatically appears in both the theme list and the top page's new arrivals.

The list page is built in Views, with taxonomy set as the extraction condition and a term set as the filter. Articles tagged as Life Style therefore appear on the list page created through Views at /Life Style. This page is used as a menu link.

Separate from this, a list page is generated by taxonomy alone. This appears when you click the Tag: Life Style link displayed at the bottom of an article.

2-2. Using Taxonomy as a Category List

The vocabulary named "Article category" has terms configured to match article content:

  1. Old-Clothes Article.
  2. Fashion Article.
  3. Watch Article.
  4. Photo Article. 

Like the Tags vocabulary above, Views could also be used here, but since that's not currently needed, the pages generated by each term are being used directly as category lists. Links to these category lists are placed in the menu.

Clicking the Article category: Old-Clothes Article. link at the bottom of a published article also displays the same list.

3. Taxonomy Configuration

Vocabularies and terms are created in Structure > Taxonomy.

3-1. Adding a Vocabulary

+ Add vocabulary

Enter the name, description, language, and term language settings, then save.

The newly created vocabulary appears in the Taxonomy vocabulary list.

By default, the term list is displayed. Clicking the dropdown next to a vocabulary and selecting Edit gives access to:

  1. List
  2. Edit
  3. Manage fields
  4. Manage form display
  5. Manage display
  6. Manage permissions
  7. Translate taxonomy vocabulary

Fields configured here are reflected in the actual terms created within the vocabulary. Through fields, various elements can be added to the list pages generated by terms. I'm using the defaults, but the term description field supports HTML, so I use it to add a description for each category list.

3-2. Adding Terms

Structure > Taxonomy > Manage > Edit Article category > Article category

  1. + Add term
  2. Enter the name, description (HTML), Relations > Parent terms, Revision information, and URL alias settings, then save.
  3. Name: Old-Clothes Article.
  4. Relations > Parent terms: none specified. Hierarchy is possible here but is administrative only — it's a different concept from hierarchy on the web.
  5. Revision log serves as an admin note.
  6. The URL alias defaults to term-xxx. Without the term- prefix, the Views rule won't generate a list page. I've set it to term-lifestyle-old_clothes.

That completes the term setup.

4. Adding a Field to a Content Type

Since taxonomy is a label feature attached to articles, the content type needs to be configured to carry that taxonomy.

In Structure > Content types, configure the page type that will carry the taxonomy, then add the taxonomy as a field to the selected content type.

The following article covers this in detail — please refer to it.

#C15 Using Content and Structure.

Covers an example of configuring a content type and creating a page with a specified content type. After configuring taxonomy, a taxonomy field is added to the content type, and the appropriate term is selected when creating the published article.

The example above assigns configured terms to actual articles and uses them for list generation after publication.

Conclude.

A brief overview of Drupal's Taxonomy. It's a broad-strokes summary, but the key takeaway should be that Drupal's Taxonomy feature is a system for freely attaching labels to articles. How those labels are then used to work with articles is what comes next.

To summarize this article:

  1. Taxonomy is a label system for sorting articles.
  2. Configure multiple taxonomies to match your purpose.
  3. To use taxonomy, configure vocabulary > terms — those terms then function as tags or categories.
  4. To use configured terms, the vocabulary must be specified as a field in the content type being used.
  5. Giving articles a term generates a taxonomy list page that can be used as a category list.
  6. Setting taxonomy as the extraction condition in Views and using vocabularies or terms as filter conditions enables more flexible list creation.

The next article walks through actual examples of taxonomy in use.

Next article.

Drupal Taxonomy Part 2

A walkthrough of taxonomy in practice, looking at actual articles and pages on the site that use it.

Last update
Contributor
S.Takeda
Article

Powered by Drupal 11.4.2 and Bootstrap 5.0.4

Published AWS Jamstack by Drupal