Drupal Taxonomy Part 2

The previous article covered an overview of Drupal's Taxonomy. This one walks through actual usage examples.

A quick recap of taxonomy:

Taxonomy Concepts

  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.

Let's look at usage examples using articles I've created.

Taxonomy in Practice

Let's see what happens when labels are attached to articles and used for sorting.

The articles on my site broadly fall into two themes:

  1. A personal record of building a website while learning Drupal > Creation
  2. Articles on fashion and vintage clothing > Life Style

A term called Creation and a term called Life Style are configured for these two themes respectively.

When writing a Life Style article, the Life Style content type is selected and the article is written. Before publishing, Life Style is selected in the Tags field.

As a concrete example, here's the article:

#L17 Leica SL2-S

The published page displays the following at the bottom:

Published: 2024-10-08
Author: S.Takeda
Tag: Life Style
Article category: Photo Articles.
Shop: Leica Ginza Store

Tag, Article category, and Shop here are all taxonomy.

Tag = vocabulary: Life Style = term
Article category = vocabulary: Photo Articles. = term
Shop = vocabulary: Leica Ginza Store = term

The content type's fields for this article are assigned the vocabulary fields configured in Taxonomy. When creating an article, those fields appear alongside CKEditor and the rest. Selecting a vocabulary field activates autocomplete, showing the registered terms — the appropriate term is selected to match the article content. Selecting a term during article creation causes that term to appear on the published article.

The configured terms appear as links at the bottom of the page. Clicking a link shows a list of all articles assigned the same term. That's the basic use of taxonomy.

1. Using Taxonomy as Tags

Giving articles taxonomy elements and displaying the assigned terms lets taxonomy function as what's generally called a tag. As covered in the previous article, the basic concept of tags is that they have no hierarchy. A tag cloud — the kind you often see on blogs, listing all tags in one place — is a feature that displays registered tags from a separate field on a separate page.

My own approach to site building is to keep categories small since it's a small site, so I don't use fine-grained tags in large numbers — meaning there's no current need for a tag cloud. But as articles accumulate, it could help readers find what they're looking for, so I'll consider adding one when the time comes.

Published: 2024-10-08
Author: S.Takeda
Tag: Life Style
Article category: Photo Articles.
Shop: Leica Ginza Store

The terms configured in the article — Tag, Photo Articles., and Leica Ginza Store — are functioning as tags.

The word "tag" is used, but the function is to place article-related labels on the page so that articles sharing the same label can be listed and displayed together. The typical purpose is to surface related articles for readers, or to organize keywords that don't quite warrant a full category.

2. Using Taxonomy as Categories

Placing configured terms as a list in a menu gives taxonomy category-like functionality. On my site, the top navigation includes a navigation menu where categories can be selected.

Top navigation menu

|-- Home
|
|-- Life Style articles
|    |-- All articles | Created in Views with taxonomy > Tags > Life Style as the extraction condition
|    |-- Vintage clothing articles | Display result of Article category > Old-Clothes Articles.
|    |-- Fashion articles | Display result of Article category > Fashion Articles.
|    |-- Watch articles | Display result of Article category > Watch Articles.
|    |-- Photography articles | Display result of Article category > Photo Articles.
|    |-- Recommended shops | Display result of Article category > Shop List.

The link destinations use the list pages generated by each term configured in Taxonomy. "All articles" is created with Views — using taxonomy with Views will be covered separately in the Views article, so I'll skip it here.

The same taxonomy element is used both as a tag feature for finding related articles from within an article, and as a category list for browsing by category from the menu. "All articles" uses Views, but the content matches what the taxonomy link would show. Using the taxonomy display result for the menu list would also work, but there are a few advantages to using Views. I'll cover that in a separate article.

3. Advanced Uses of Taxonomy

Beyond the typical tag and category uses, here are some other ways to put taxonomy to work.

3-1. Shop Introduction Pages

One way I'm using taxonomy is for shop introduction pages.

Shop List.

Shop: Leica Ginza Store

Used both as a tag element within articles and as the basis for a separate list page used as shop information.

Shop directory: Shop List.

A Shop vocabulary is configured in articles, with individual shops used as terms. As mentioned in the previous article, the taxonomy display results can have fields freely configured — by default, a description field is provided before the list view, and it supports HTML. I use this field to add information about the shop, while the articles about items purchased there are displayed in the list view below.

One advantage of this approach is that articles about items purchased at a shop are automatically added to that shop's page. The same result could be achieved with Views or Block layout, but those would add more items to manage. Setting a shop as a term in taxonomy handles both the shop introduction and the related articles in one step, making it more efficient to maintain.

I haven't found a solution yet, but I've been trying to use terms within terms — managing the shop list itself as terms — and not getting the result I expected. Thinking through the fundamentals, it makes sense: the basic premise of taxonomy is labels for content, so a term with no content associated with it can't display. I understand that much.

Not covered in this article, but taxonomy display is also managed through Views. I want to take a closer look at that configuration at some point. Views filtering conditions are generally based on constants, but taxonomy-related Views use variables as their basis — understanding that distinction might be where the solution lies.

3-2. Latest Articles on the Top Page

Drupal's default feature for displaying articles and pages on the top page only lets you toggle each page's visibility — it doesn't support automatically displaying the three most recent articles per theme in descending order. That kind of configuration is achievable by combining taxonomy, Views, and Block layout. It requires configuration across multiple features, but it lets you display the right information in the right place in the right form.

The top page displays three latest articles per vocabulary, from two different vocabularies.

  1. Top page
  2. Creation
  3. Life Style

Vocabularies configured in taxonomy are turned into blocks in Views, then displayed on the top page via Block layout.

Three latest articles from each of the two themes are displayed. These latest article blocks are created in Views using taxonomy as the extraction condition and filtering by vocabulary, then placed on the top page through Block layout.

Conclude.

Drupal's Taxonomy has been covered across two articles. Compared to other features, the configuration and usage are relatively straightforward, which makes it versatile. Since its purpose isn't fixed, thinking through how to use it opens up a wide range of applications.

At its core, it's a feature for attaching labels to articles and pages and using those labels in various ways — and it's the foundational feature for thinking through where and how to display individual articles and pages across the site.

I often talk about Drupal's underlying concepts, and taxonomy is no exception — it's built around vocabulary > term. I also often mention that one of Drupal's characteristics is its separation of configuration from use, and that applies here too: fields and other settings are configured at the vocabulary level, while actual use happens through terms.

This means terms can be given page-like elements, making it easy to use them in ways that go beyond typical taxonomy use cases. Creating and managing shop introduction pages through taxonomy — as introduced here — isn't something I'd naturally think to do in other CMSes, but it's an idea that came from working with Drupal's configuration-versus-use separation and looking carefully at what's configurable.

As I often mention in other articles, the need to configure across multiple features comes with a correspondingly high degree of freedom and versatility — and that's one of Drupal's strengths. Writing these taxonomy articles, it's clear that combining taxonomy with Views and Block layout opens up even more possibilities.

The next article will cover Views.

Next article.

Drupal Views Part 1 — Pages

An overview of the Views feature, which lets you list created articles and pages by condition and place them freely anywhere on the site.

Last update
Contributor
S.Takeda
Article

Powered by Drupal 11.4.2 and Bootstrap 5.0.4

Published AWS Jamstack by Drupal