0

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

1

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.

2
  • Thanks. But what do you mean with ER?
    – Arcy
    Jul 28 '20 at 8:56
  • Entity Reference, it's the field on your Content Type that you create to reference a Taxonomy term.
    – prkos
    Jul 28 '20 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.