Drupal - Taxonomies
Drupal - Taxonomies
Section titled “Drupal - Taxonomies”Taxonomy is Drupal’s system for classifying and organizing content. It allows you to group content items together based on shared characteristics. Think of it as creating categories, tags, or keywords for your site.
Drupal’s taxonomy system is built around two main concepts:
- Vocabularies: These are containers for groups of terms. For example, you might have a vocabulary called ‘Categories’ or ‘Tags’.
- Terms: These are the individual labels or keywords within a vocabulary. For example, in a ‘Categories’ vocabulary, terms might be ‘Technology’, ‘Sports’, ‘Health’.
Follow these steps to work with taxonomies:
Step 1: Navigate to the Taxonomy Page
Section titled “Step 1: Navigate to the Taxonomy Page”In the administration toolbar, click ‘Manage’, then go to ‘Structure’, and then click ‘Taxonomy’ (usually /admin/structure/taxonomy).
Step 2: Add a Vocabulary
Section titled “Step 2: Add a Vocabulary”If you need a new grouping system (e.g., ‘Product Types’, ‘Event Categories’), you’ll start by creating a vocabulary.
-
On the Taxonomy page, click the ’+ Add vocabulary’ button.
-
You’ll see a form with the following fields:
- Name: Enter a descriptive name for your vocabulary (e.g., ‘Article Categories’, ‘Department Tags’). This is a required field.
- Description: (Optional) Provide a brief description of what this vocabulary is for.
- Click ‘Save’.
Your new vocabulary will now appear in the list on the Taxonomy page.
Step 3: Add Terms to a Vocabulary
Section titled “Step 3: Add Terms to a Vocabulary”Once a vocabulary is created, you can add terms to it.
-
On the Taxonomy page, find the vocabulary you want to add terms to and click the ‘Add terms’ button in its ‘Operations’ column.
-
You’ll be taken to a form to add a new term. Key fields include:
- Name: The name of the term (e.g., ‘Drupal Development’, ‘Frontend Techniques’). This is required.
- Description: (Optional) A more detailed description of the term. This can be useful if the term itself isn’t fully self-explanatory.
- Text format: (For the description field) Select the text format for the description, if you are using HTML.
- URL alias: Drupal automatically creates a path like
/taxonomy/term/[tid]. You can specify a custom alias (e.g.,/category/drupal-development). The ‘Pathauto’ module is highly recommended for automatically generating user-friendly aliases based on term names. - Relations:
-
- Parent terms: If you want to create a hierarchical vocabulary (e.g., a category with sub-categories), you can select parent terms here. Start typing the name of an existing term in the same vocabulary to select it as a parent.
-
- Weight: Terms can be ordered by weight. Lower numbers appear first. This is useful for controlling the display order of terms in lists.
- After filling in the details, click ‘Save’.
Repeat this process to add all necessary terms to your vocabulary. You can view, edit, or delete existing terms by clicking ‘List terms’ for a vocabulary.
Using Taxonomies with Content
Section titled “Using Taxonomies with Content”To use a vocabulary with your content (e.g., to tag articles with categories), you need to add a ‘Term reference’ field to your content type:
-
Go to ‘Manage’ > ‘Structure’ > ‘Content types’.
-
For the desired content type, choose ‘Manage fields’ from its operations.
-
Click ’+ Add field’. Select ‘Reference’ > ‘Taxonomy term’ as the field type.
-
Give it a label (e.g., ‘Category’) and configure it to use the vocabulary you created.
Now, when creating or editing content of that type, you’ll be able to select terms from your vocabulary.
Practical Applications: Taxonomies are fundamental for organizing content, creating faceted search filters, displaying related content, building category-based navigation, and much more.