Showing Drupal taxonomy terms' hierarchical structure in Views

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:

Hierarchical vocabulary sample complex structure

Steps:

  1. Create a view. Make sure to select "Taxonomy terms" under "Show" field:

    Create a view hierarchical vocabulary structure

  2. Add a relationship, select "Taxonomy term: Content using Type" and click "Apply" button:

    Add vocabulary and node relationship

  3. Check the "Require this relationship" checkbox and click "Apply" button:

    Vocabulary and node relationship settings

  4. 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:

    Add parent term relationship

  5. Make the value of "Identifier" and "Administrative title" text fields to "Parent level 1"

    First level parent term relationship settings

  6. Add another relationship for the second level, select "Taxonomy term: Parent term" and click "Apply" button:

    Add parent term relationship

  7. Make the value of "Identifier" and "Administrative title" text fields to "Parent level 2"

    Second level parent term relationship settings

  8. Add another relationship for the third level, select "Taxonomy term: Parent term" and click "Apply" button:

    Add parent term relationship

  9. Make the value of "Identifier" and "Administrative title" text fields to "Parent level 3"

    Third level parent term relationship settings

  10. Now let's add a field to display the node's title, select "Content: Title" and click "Apply" button:

    Add node title field

  11. Uncheck the "Create a label" checkbox, check the "Link this field to the original piece of content" checkbox and click "Apply" button:

    Node title field settings

  12. 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:

    Add parent term name field

  13. Select "Parent level 1" under Relationship" field, uncheck the "Create a label" checkbox, check the "Exclude from display" checkbox and click "Apply" button:

    First level parent term name field settings

  14. Add another field for the second level, select "Taxonomy term: Name" and click "Apply" button:

    Add parent term name field

  15. Select "Parent level 2" under Relationship" field, uncheck the "Create a label" checkbox, check the "Exclude from display" checkbox and click "Apply" button:

    Second level parent term name field settings

  16. Add another field for the third level, select "Taxonomy term: Name" and click "Apply" button:

    Add parent term name field

  17. Select "Parent level 3" under Relationship" field, uncheck the "Create a label" checkbox, check the "Exclude from display" checkbox and click "Apply" button:

    Third level parent term name field settings

  18. 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:

    Existing term name field settings

  19. Under the format criteria, click the "Settings" of "Unformatted list". And make its settings same as the following screenshot:

    Display format settings

  20. (Optional) set the pager to "Display all items" and click "Apply" button:

    Pager settings

  21. The views preview outputs something like this:

    Views result output

    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

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!

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.

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,

Work perfect, help me a lot.
Thanks

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.