This guide will show how to display Drupal taxonomy terms' hierarchical structure in Views. It is assumed that you have already existing setup of your own taxonomy terms hierarchical structure, a content type which has a field referencing your vocabulary with taxonomy terms hierarchical structure and posted nodes of this content type tagged with one of these taxonomy terms.
In this guide we will use the Drupal vocabulary that has the following structure as our example:
Steps:
-
Create a view. Make sure to select "Taxonomy terms" under "Show" field:
-
Add a relationship, select "Taxonomy term: Content using Type" and click "Apply" button:
-
Check the "Require this relationship" checkbox and click "Apply" button:
-
Our example taxonomy terms' hierarchical structure has three levels so we will add three more relationships. Let's create the first one. Add another relationship, select "Taxonomy term: Parent term" and click "Apply" button:
-
Make the value of "Identifier" and "Administrative title" text fields to "Parent level 1"
-
Add another relationship for the second level, select "Taxonomy term: Parent term" and click "Apply" button:
-
Make the value of "Identifier" and "Administrative title" text fields to "Parent level 2"
-
Add another relationship for the third level, select "Taxonomy term: Parent term" and click "Apply" button:
-
Make the value of "Identifier" and "Administrative title" text fields to "Parent level 3"
-
Now let's add a field to display the node's title, select "Content: Title" and click "Apply" button:
-
Uncheck the "Create a label" checkbox, check the "Link this field to the original piece of content" checkbox and click "Apply" button:
-
To display the node's tagged term name as well as all its parents term name, we will add the three levels parent term name but we will hide in field criteria as we will use this in grouping in format criteria. Add a field for the first level, select "Taxonomy term: Name" and click "Apply" button:
-
Select "Parent level 1" under Relationship" field, uncheck the "Create a label" checkbox, check the "Exclude from display" checkbox and click "Apply" button:
-
Add another field for the second level, select "Taxonomy term: Name" and click "Apply" button:
-
Select "Parent level 2" under Relationship" field, uncheck the "Create a label" checkbox, check the "Exclude from display" checkbox and click "Apply" button:
-
Add another field for the third level, select "Taxonomy term: Name" and click "Apply" button:
-
Select "Parent level 3" under Relationship" field, uncheck the "Create a label" checkbox, check the "Exclude from display" checkbox and click "Apply" button:
-
Now let's edit the existing "Taxonomy term: Name" under field criteria, uncheck the "Create a label" checkbox, check the "Exclude from display" checkbox and click "Apply" button:
-
Under the format criteria, click the "Settings" of "Unformatted list". And make its settings same as the following screenshot:
-
(Optional) set the pager to "Display all items" and click "Apply" button:
-
The views preview outputs something like this:
The native views theme isn't pretty for this application but it clearly display our sample taxonomy terms' hierarchical structure with their nodes tagging these terms.
Comments
The images are complete in…
The images are complete in this article. Please try to click Refresh in your browser. Thanks.
tried to follow for Drupal 8
These are the most comprehensive instructions I've found to do this, but my parent header is repeating like this:
Forms_IT
General Forms
GeneralForm1.doc
Boston Forms
Directions.doc
Forms_IT
General Forms
OT Approval Forms
OTForm1.doc
OT Approval Forms is supposed to be a taxonomy under General, but it's not doing it correctly. I want it like this:
Forms_IT
General
Administrative.doc
OT Approval
Overtime Approval.doc
Quincy
Directions.doc
Any ideas- thanks so much for getting me this far!
Try to enable "Distinct"
Try to enable "Distinct" under "Query settings".
Aaron (not verified)
Wed, 12/09/2020 - 07:54
In reply to tried to follow for Drupal 8 by kzeeh (not verified)
D8 won't help you...
This, like most things, simply doesn't function with the maximized complexity of D8. The grouping works *ok* for two levels, but for any more, the children just get appended to the list outside the hierarchy.
This does not work here
Hi,
Thanks for your tip. In my Drupal 9 setup, there is no tree, no hiearchical structure. Level 1 appears, and Level 2 and level 3. Grouping is not working. How to solve this?
Thanks,
Sorry, the article above was…
Sorry, the article above was for Drupal 7 sites. I will post a separate article for Drupal 8 and 9.
Fareed Fattal (not verified)
Wed, 05/04/2022 - 01:58
In reply to This does not work here by Alexander (not verified)
Views Taxonomy Term Name Depth
You can use (Views Taxonomy Term Name Depth) module to achieve this.
Super
Work perfect, help me a lot.
Thanks
missing Image
Does the Screenshot under point 19 is missing on purpose?