I'd like to have a view block on my content page that shows ALL related content. ALL in the sense of chaining - if Node A references Node B which references Node C which references Node D, then nodes B, C, and D all show up on Node A's page even though it itself is only related to Node B. How can I set this up?


One way of doing this in a non-programmatic way is to use views_field_view. With this method you will only get a set number of nesting levels - for example 4 levels: create a view of your specific node Content Type with 4 Pages, A, B, C, and D. In Page A, insert a Views Field that references Page B, in B a field to Page C, and in C a reference to page D. Pages B, C and D should have a contextual filter for a Node ID (nid). In each page, the Views Field View field should pass the Node Reference as an argument to the next Page. I hope this is clear. Let me know if it's not, and I can expand this.

EDIT: If you are looking for "infinite depth" I suggest that you look at the programmatic alternative for Views, EntityFieldQuery(). Perhaps a recursive call to a function that does the query, while you build a global multi-depth array with the data you need, then theme it as a table.

  • Thanks for this idea. Though I'm really looking for non-defined depth. – digitgopher Nov 2 '15 at 22:17
  • See my edited suggestion – argiepiano Nov 2 '15 at 22:55
  • 1
    Re: my edited answer. Using a recursive function will allow you to have infinite depth, but you also run the danger of getting into an infinite loop if one of the children nodes references a node above itself. – argiepiano Nov 2 '15 at 23:49
  • 1
    Then don't use recursion but rather keep iterating until you no longer have references to follow. Have an array contain all node IDs found so far and only add to it if the node ID doesn't already exist. Good luck. – Mario Awad Nov 3 '15 at 19:22

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.