0

Using Drupal 7

I have a hierarchical taxonomy each node in the site is assigned a taxonomy to identify where it sits in the site structure.

On certain pages (landing pages) I would like to show the children of those pages but not the page itself nor importantly any peer pages

so in the following taxonomy

  • parent1
    • child1
    • child2
    • child3
  • parent2
    • child4
    • child5
    • child6

I have two nodes assigned the "parent1" taxonomy and a node assigned to each of the child taxonomies

If I go to one of the nodes assigned the parent1 term I should see in my block view all the nodes assigned to child1-3

Currently using "taxonomy term with depth" I see all the correct children, but I also see the other node assigned to the parent1 term because taxonomy term with depth, returns all children plus the parent nodes.

Hiding the node I am on is easy with exclude, but I cannot see a way of hiding other nodes with the same term as the page I am on.

How can I select only the child nodes, not the child plus parent nodes?

1
  • I have found a solution to this problem - typical! I will post it when I am allowed to answer my own question. but I am still very interested to hear how other people might solve this to see what alternatives are possible. Commented May 14, 2019 at 1:48

1 Answer 1

1

It turns out the problem was not as hard as I thought. The hard part was to know what relationship to set up and what contextual filter to implement.

I solved it by doing the following

  • Created a view of content using fields
  • Created a contextual filter using "has taxonomy term with depth"
    • Selected default value of taxonomy term ID from URL
    • Set it to depth 1 to pick up children
    • Limited to my vocabulary

That part was obvious. The next part is what caused issues and was not obvious. I could not find an example anywhere on how to do it.

It is easy to exclude the current page by using the nid contextual filter and using the "exclude" option under the "More" section. This is the answer found by searching online. The problem is it does not resolve the "peer" content issue. It would only remove the current node and not other nodes with the same term.

To fix that problem I found that when I added a relationship, a new contextual filter previously not available was added to the list and it had the all important exclude feature.

So I

  • Added a relationship using my taxonomy (Content)
  • Added a new contextual filter "term ID" previously not available
    • Selected default value of taxonomy term ID from URL
    • Limited it to my vocab (probably not necessary)
    • Set exclude under the More section

This removed all the nodes with the same taxonomy term as the current node, including the current node, leaving only the children nodes

Your Answer

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

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