TransWikia.com

List of parent and child taxonomies and related content

Drupal Answers Asked by Arcy on December 19, 2021

I would like to show in the front page a list of dishes. Like a real restaurant menu, I would like see:

Wines

 -Whites

  --Product 1

  --Product 2

 -Reds

  --Product 3

  --Product 4

Beers

 -Blondes

  --Product 5

 -Reds

  --Product 6

and so on.

To do so, I created a taxonomy vocabulary named category and then a list of terms and sub-terms like this:

taxonomies

Then in my custom type Product I created a relation field to the taxonomy category.
But when I tried to create a custom view to list all the products by taxonomy terms and sub-terms, I only view the child one.
How can I create the view to display the complete hierarchy list?
Thanks

One Answer

There is more than one way of solving this.

If you start from your existing case of Content Views and listing your Products, you can add the Taxonomy ER Field. This field will show the Term that the node is directly linked to, the "child" in your Taxonomy hierarchy.

To get the "parent" Taxonomy term you have to add the Relationship for the ER field in question. Once you add that you will be able to access the Parent Field from the "Taxonomy term" Category.

You can then set Grouping under Format Settings. Set the first grouping to the "Parent" Field, and the second one to the "child" regular taxonomy field.

You can hide the taxonomy fields with Exclude from display since they'll appear in the grouping output.

Alternatively, you can add a second Relationship on top of the first one, for the Parent of the term, but that approach isn't necessary unless you have 3 levels of taxonomy hierarchy, and it can add to the performance strain.


You can also start from the Taxonomy term type Views, show hierachy with Depth, and use a Relationship to add the nodes/content into the View.

Answered by prkos on December 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP