0

In Drupal 8, I have a hierarchical taxonomy vocabulary called "Living Things" containing these terms:

Animals
--Fishes
----Blennies
------Yellow Blenny
------Green Blenny
----Gobies
------Blue Goby
------Red Goby

I have created a custom content type called "Taxon Page" which includes a single reference to the "Living Things" vocabulary.

Using the "Taxon Page" content type I have created a page for each of the terms in the "Living Things" vocabulary. So for example, my "Yellow Blenny Facts" content page contains a reference to the "Yellow Blenny" taxonomy term.

On those "Taxon Page" content pages, how can I display only content that references that taxonomy term's immediate children (if there are any)? For example, the "Fishes Facts" content page should display data from the "Blennies Facts" and "Gobies Facts" content (not just a link to those taxonomy terms), but not their children.

I have tried to achieve this by creating a view for "Content type (= Taxon Page)" and adding a "contextual filter: Content: Has taxonomy term ID (with depth)" (depth of 1) but it did not work.

Note that this question is related but different, as it only refers to taxonomy terms, not content referencing those taxonomy terms.

5
  • lol Let's start again with a question: It's not actually clear whether you like to show content pages (e.g. pages with a "Blennie" term reference) or the taxonomy page content (term descriptions) on your taxon page content type. It's somehow mixed up in your description... Dec 6, 2017 at 13:36
  • I would like to show content pages, since I want an image and some further info to display. Sorry for the confusion. I have added the word "Facts" to my "Taxon Page" names to try and help clarify it.
    – Nick Hope
    Dec 6, 2017 at 13:52
  • You can add images and further information to the taxonomy terms as well. Taxonomy terms are fieldable. So by providing an according description and e.g. an image field, you can attach all required information to the term itself and don't have to create a taxonomy term AND a content type with this term. - You may as well just use a Fishes only content type without taxonomy terms at all and add an entity reference field to the parent Fish. Then you'd build Content (node) views. Which suits best always depends on your actual real use case. Dec 6, 2017 at 14:42
  • I (and Patrick) added further comments regarding your first option (i.e. Just use taxonomy terms, not content) below his answer. That approach seems promising and takes us back to the original question (LOL!). Your 2nd option (i.e. forget taxonomy and just build a hierarchy via content) is an interesting approach which I will consider, but I suspect the crucial ancestral tree (breadcrumbs) might be difficult to achieve. Thanks again for your advice and patience.
    – Nick Hope
    Dec 6, 2017 at 15:22
  • Not hard to achieve with a custom breadcrumb builder, menu trails and/or url path patterns. ;) Anyway, you got several different versions for views with both your questions and a lot of different things to evaluate or to consider. Even this platform is actually not made for discussing implementation approaches, but helping with specific problems, after reading docs and learning the basics did not work. Good luck with your animals! :) Dec 6, 2017 at 15:45

2 Answers 2

0

I think you may be confused about how Views works. To give a custom display to taxonomy terms, you don't need to create a content type to reference a taxonomy and then use Views to override how the content type is displayed; you can simply create pages with a view that display the taxonomy directly.

This means you may not need the Taxon Page content type; depending on what you intend to do, you could add any fields you need for your fish pages to the Living Things taxonomy and then display this taxonomy as pages by using a view that overrides how the taxonomy is displayed.

For an example, see the taxonomy_term view included in core:

/admin/structure/views/view/taxonomy_term

Another way to do this is to use Panels, which (with Page Manager) allows you to override the display for all taxonomy terms and attach a custom view (and whatever else you want) to those terms.

Yet another option is Display Suite.

5
  • I fear as well, that a little more insights into the context of content, taxonomy terms, blocks and views would help for his use case (we all started somewhen ;). - But I think panels is a little overkill to show related items on whatever levels only. Dec 6, 2017 at 14:03
  • @MarioSteinitz Panels may be overkill if the only goal is to attach related terms, but the advantage of Panels is that it provides a UI for making a lot of changes that otherwise require coding, so it can be helpful to people who are not developers. Dec 6, 2017 at 14:06
  • Sure it is a helpful add-on for customizing the output of whatever entity and a valuable hint for further site development. (The same as tvi and display, which I'd prefer.) Just from his previous question I learned he likes to show related content or taxonomy term details only. Dec 6, 2017 at 14:12
  • I started by adding taxon details (eg pics/size/color) to the taxonomy terms themselves, as you suggest. Drawbacks of that: 1. Terms don't appear in default search. 2. Authorised users couldn't add taxon details via "Add content"; I'd have to give them write-access to Taxonomy. 3. I consider importing vocab from an external database, so adding details via a custom content type seems conceptually preferable. Drawbacks of using content type: 1. Doesn't show tree. 2. Repetition
    – Nick Hope
    Dec 6, 2017 at 14:58
  • @NickHope 1. Can be done with Custom Search module or Search API (more flexible, but more complex) 2. I don't see how this is a drawback; users need permission to edit either way 3. Taxonomy and Nodes are both entities, so again, this shouldn't be different either way Dec 6, 2017 at 15:04
0

I start by guessing that you want to show the taxonomy term descriptions of child terms on the "taxon pages".

Best way to achieve this is to creating a new block view.

As you supposedly want to show taxonomy data, choose "Taxonomy term" as data to show; save and edit.

Next you have to pull in the parent term's ID, that is referenced from the node (Content page) this block will be placed in. So add a contextual filter "Taxonomy: Parent". In "if filter value is NOT available", choose to provide a default value, taxonomy term ID from URL, and make sure to tick "load default filter from node page".

You can optionally fine-tune the settings by limiting it to your taxonomy vocabulary and define multiple value handling.

Next, save this view and place the newly created block on your content page. You do so in "Structure / Block layout". Go to the region you like to show the block in, e.g. "Content". Click the "Place block" button and find your view block.

Configure it to display only at your content type.

EDIT:

And if you like to show fields of content that has the child terms assigned, then you can add a relation in "Advanced / Relations" to content that has the term, change the view type to be a field view (if not already), and add the fields from your related content. (Didn't try this one, but should work as well.)

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.