Custom post types and taxonomies

WordPress taxonomies

Transcript

Introduction

In this lesson, we will learn how taxonomies can enhance your site’s information architecture and improve the user experience. Let’s start with understanding taxonomies in WordPress. A taxonomy is a way of grouping posts and custom post types together. Taxonomies are the method of classifying content and data in WordPress. They help organize content, making it easier for visitors to navigate your site. When you use a taxonomy, you’re grouping similar things together. There are two types of taxonomies in WordPress. Default taxonomies and custom taxonomies. Default taxonomies include categories, tags and post formats. While custom taxonomies are created using a plugin or by a developer. In this lesson, we won’t cover post formats, but we will add a link below resources if you want to learn more.

Categories

Let’s start by looking at categories. Categories are a hierarchical taxonomy, which means they can have parent and child categories. Let’s say, for example, you have a traveling website. You can create a parent category named Destinations and add different continents as subcategories. We access categories in the posts below on the left sidebar of the dashboard. As you will notice, I have already created a category called Destinations. Next, I will create a subcategory called Europe, one of the continents. So I will add the name, add the slug. The slug is the URL-friendly version of the name and is usually in lowercase. Below the parent category, we can select Destinations as the parent category for this child category. Then, go ahead and add the new category. WordPress requires at least one category for posts. So when you have a new website, you will see a default category called Uncategorized. Renaming this to something more relevant to your content is good practice.

Tags

Next, let’s talk about tags. Tags are a non-hierarchical taxonomy. They don’t have parent or child relationships. They provide a granular search mechanism, allowing users to find specific content across various categories. To continue with our traveling example, if we have destinations as our parent category and different continents as our subcategories, we can add the names of countries and cities as tags. Access tags below categories and then go ahead and add the relevant name and slug. To reiterate, a tag is a single parameter that groups similar posts based on specific details rather than overarching themes, allowing for more precise content categorization. Let’s look at one of our blog posts on the front end, namely surfing in Portugal. Below the title, we will see the categories, and below the text, we will see the tags.

Custom taxonomies

What if you want to create your own taxonomies? Creating custom post types is an excellent way to create content types beyond posts. For example, think of a movie review WordPress site. Instead of using general taxonomies, such as categories and tags, we can create a custom post type, namely Movies, and then add a category named Genre. And I will create a custom tag and call it Movie attributes. And those Movie attributes can range from awards if it is based on a true story and even the age restriction. Let’s see this in action on my test website.

Example

I have used the Custom Post Type UI plugin to create a custom post type named Movies, and a category named Genre and a tag named Movie attributes. You can learn how to create custom post types using a plugin in one of our other lessons, which we will link below this video. Now let’s go ahead and add a movie entry, namely Lion King, and in the sidebar settings on the right, below the custom Genre category, we can select Drama. Below the custom tag taxonomy, we can select Oscar-winning and PG. What if you wanted to display posts from a specific taxonomy? You can leverage the Query Loop block to create custom queries that display posts based on specific categories or tags or custom taxonomies. In this example below post type, I’ve selected my custom post type and below Filters, you can filter which posts you want to have displayed based on the relevant taxonomy.

Displaying descriptions

The last thing I want to touch on is adding a description to a taxonomy and also highlighting that the description field we can see here can be displayed in archive page templates using the Term Description block. Let’s see this in action. Let’s go ahead and add a description for my Destinations category and then update. Next, we can open up the All Archives template or, of course, create a custom Category template. For this example, let’s go ahead and use the All Archives template. If we want the description field of the taxonomy to be displayed, we can add the Term Description block. And please take note, the Term Description block only works in the archive pages. If we click on the Destinations category on the front end, the archive page will open up and we will see the description below the title.

Conclusion

Understanding and effectively using categories and tags, as well as custom taxonomies, is crucial for organizing your WordPress site’s content. By structuring your content with these taxonomies, you enhance the user experience, making it easier for visitors to find what they want.

Resources

  1. Creating custom post types and taxonomies (opens in a new tab)
  2. Post formats (opens in a new tab)

Practical

Use WordPress Playground to apply your knowledge:

  • Step 1: Create three posts, namely Colosseum, Central Park, and Table Moutain.
  • Step 2: Create a parent category, namely Destinations.
  • Step 3: Create three sub-categories: Europe, North America and Africa.
  • Step 4: Create multiple tags such as Italy, USA, South Africa, Rome, New York, and Cape Town.
  • Step 5: Apply the categories and tags to the relevant posts.
  • Step 6: View your posts, categories, and tags on the front end.
  • Step 7: Update how you want the Query Loop block to display your blog page or archive page.
This is a preview lesson

Register or sign in to take this lesson.

Suggestions

Found a typo, grammar error or outdated screenshot? Contact us.