5

I think my problem is quite simple but I don't manage to find the solution on the internet (I found solution for Drupal 7, but they don’t apply to Drupal 8).

I have a taxonomy like :

  • Fruits
    • Red fruits
      • Strawberry
      • Raspberry
    • Black fruits
  • Vegetables

Using Views in Drupal 8, with the preconfigured Taxonomy term, I'd like that when I click on a parent, it displays all the children terms and the nodes within these children terms. (eg. when I click on Fruits, it display all nodes in Fruits, Red Fruits, Strawberry, Raspberry and Black fruits ; and when I click on Red fruits, it displays all nodes within Redfruits, Strawberry and Raspberry).

Indeed, by default, when you click on a parent term, it only shows nodes within this parent term, but not those who belong to children. (eg. when I click on Red fruits, it only display nodes within Red fruits, but not those in Strawberry or Raspberry)

1 Answer 1

6

I finally found the solution. My Drupal is in french, I tried to translate, but my translation may not match the exact words :)

Go to View and edit the default Taxonomy term (content) page. In Contextual filters :

  1. select "possède l’identifiant de terme de taxonomie (avec profondeur)" and configure like this :
    • depth : choose the depth you want
    • check Allow multiples values
    • check Provide a default value and choose Taxonomy term (ID) from URL
    • select Filter by elements that share all terms
    • check Override title and write {{arguments.tid}} in the field
    • check Specify selection criterion and choose Taxonomy term (ID)
  2. select "possède l’identifiant de terme de taxonomie avec modification de profondeur"

Now, if you have a complex taxonomies, go on a taxonomy term page may display the same result several times. To prevent this, in your View, go to Other section (under Contextual filters) and click on Query parameters. Then check Distinct.

Enjoy !

Step 1 Step 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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