Drupal - How to show terms in a Views in its hierarchical structure?
I would recommend that you give a try to Views Tree module which installs a tree-style (adjacency) Views style plugin which allows you to list vocabulary in a hierarchical way.
Comment: Views Preview does not show the tree layout but normal page display does output as a tree.
Views Tree is nice for fast and simple hierarchy configuration but it lacks some features like different fields/configuration for different tree levels and grouping
You can get more flexible configuration with Views Field View.
This is the setup I needed for a taxonomy tree of three levels where I needed grouping by top level term.
- Create a view of terms with a page display(or any other display)
- Add relationship "Taxonomy term: Parent term"
- Add Field : Term name(without relationship), Term Name(Parent relationship, excluded from display)
- Add Filter Taxonomy term: Parent term (Parent relationship) equal to 0. (show only level 2)
- In Format settings, use grouping with field (Parent) Term Name.(to display level 1)
- Add A new display (an attachment is good)
- Override its fields (just click any field, choose this attachment(overridden) from the select box on top, and then save the field. (this is to avoid recursion)
- Override the attachment Contextual filters by adding Taxonomy term: Name (Parent relationship)
- Add a view field (Global: View) to your view fields.
- Use the attachment in the view field config, and add the token for the term name (not the parent) as the contextual filter value sent to the attachment.
You can remove the relationship from the filter in step 4, this will display the top level in main display, so you can skip grouping (step 5), then add a new display for each level you want to display (control no. of levels to display)
For me this gave almost the same results of Views Tree but with the flexibility I needed.
I've solved similar task by using the Taxonomy menu module.
Transform any of your taxonomy vocabularies into existing menus easily!
Features:
- Custom Menu per vocabulary
- Uses the Terms default Path
- Integrate with Views
- Integrate with Path Auto
- Customize the menu path to anything using hooks: Developer Documentation for version 6.x-2.x
- It doesn't interfere with other menu modules