Node Hierarchy lets you assign parent/child relationships to nodes, which can be displayed in Views.

In Views, you can display the parent of a node, the ancestor of a node and the child of a node. (Instructions below*).

Is there are any way to combine this to display the immediate children of the top level parent node?

If not, are there any other modules that would allow this. (I have tried both relationship and entity references, but they don't seem capable).

*Instructions on how to display Node Hierarchy relationships in Views.

How to display Parent Node: In Views, Go to relationships and enable the Node Hierarchy Parent relationship. Then go to contextual filters, and selected Node ID as a filter. Under "When the filter value is available" set the Validator to content.
Create a block display and place it on your node.

How to display Ancestor Nodes: Exactly the same as Parent Node, but the Node Hierarchy Ancestor Relationship is used.

How to display Child Nodes: This requires a different approach from the above two, as a relationship is not used. The "Node Hierarchy: Parent Node ID" is used as a contextual filter in place of Node ID, however, the settings are the same.

2 Answers 2


You could try adding parent node as a relationship in views, then add a filter and set it to "is empty (NULL)" as a requirement of the field with relationship parent. This will only display nodes that have no parent node set.

If you want to show only nodes whose parents have no parent, you'd add a second relationship (called something like "grandparent") and then set your filter to require the grandparent, rather than the parent, to be empty.


This code, if put in the template file for a view that is set to display at url http://yoursite.com/[some word]/[taxonomy term]. It takes [taxonomy term], finds the TID from the name (so if you have TID in the URL you can skip that part), and creates an array of ancestors called $ancestors_list (in mine they happen to link to a view at http://yoursite.com/[some word]/[new taxonomy term] that takes taxonomy terms as a contextual filter).

        if (!empty($args[1])){
            $term_name = $args[1];
            $terms = taxonomy_get_term_by_name($term_name);
            foreach($terms as $term){
                $tid = $term->tid;   //find the TID for the term name
            $pedigree = taxonomy_get_parents_all($tid);         //get the tree for the term and create an array of parent terms
            $ancestors_list = array();
        foreach($pedigree as $ancestor){
            $ancestor_name = $ancestor->name;
            if ((isset($term_name) && ($ancestor_name !== $term_name)) || ($args[0]=='node')){
                $ancestors_list[] = l($ancestor_name, '[some word]/'.$ancestor_name);

I believe this list is created in order from child -> parent -> grandparent, so the top-level term would be the last in the array and the immediate child of the term would be the second to last.

  • Thank you your kindness and generosity. However, I am using Node Hierarchy and not Taxonomy. Is there a way to make that code work with Node Hierarchy? I tried experimenting with it but couldn't get it to work. If you can post a working solution, I will gladly award you with bonus bounty points, as I am touch by your generosity! Node Hierarchy can be found at: drupal.org/project/nodehierarchy
    – big_smile
    Aug 11, 2012 at 20:57
  • Ah, I see, my bad. I'll take a look.
    – beth
    Aug 11, 2012 at 21:06

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.