We can show the taxonomy terms as hierarchical structure or tree structure by using views.
For example:
Vechicle is Vocabulary
Car
Honda
Audi
BMW
Maruthi Suzuki
Marithi
Suzuki
Bike
Hero Honda
Hero
Honda
Hero
TVS
Bajaj
Bus/Lorry
Ashok Layland
Volvo
Benz
Answer:
We can use Views Tree or Views Field View module to handle this kind of tree structure.
Please follow the below steps to show a taxonomy terms as tree view, by using Views Field View
1. Add new view (View name, Show -> Taxonomy terms, Either Page or Block display)
2. Add Relationship for "Taxonomy term: Parent term" name as "Parent" in Advanced section
3. Add Fields : Taxonomy term: Name (without relationship), Taxonomy term: Name(Parent relationship, excluded it from display)
4. Check or Add Filter Criteria "Taxonomy vocabulary: Machine name" to vocabulary name
5. Add Filter Criteria "Taxonomy term: Parent term" (with Parent relationship) equal to 0. (show only level 2)
6. In Format settings, Grouping field Nr.1 with field (Parent) Taxonomy term: Name.(to display level 1)
7. Add Sort Criteria, "Taxonomy term: Weight" (with Parent relationship) to Asscending order
8. Save it
The above steps to show the two level tree structure. If you want to show three level tree structure, then you have to add the below steps,
Enable Views Field View module
9. Add A new display (an attachment is good)
10. 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)
11. Override the attachment Contextual filters by adding Taxonomy term: Name (Parent relationship)
12. Add a view field (Global: View) to your view fields in the first first view.
13. 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.
14. 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)
No comments:
Post a Comment