Node Hierarchy code examples
This page is for helpful code examples that others may also find useful when working with Node Hierarchy. Please add examples as comments -
Node Hierarchy is a module which allows nodes to be children of other nodes creating a tree-like hierarchy of content.
The module offers:
Go to Administer>>Content Management>>Modules and enable the Node Hierarchy module.
You must then tell the module which node types can be parents and which can be children. To do this you can either:
You can also pick a default node for each given type. For example, you can create a page called "Blogs" and have nodes of type "blog" be a child of that page by default.
You will need to assign the following permissions to the appropriate users:
To assign a parent to a node, either:
To create a menu for a node, edit the node, expand the Node Hierarchy fieldset and check the "Create Menu" box. Click Submit.
If the node's parent has a menu item, a new menu will be created for the node under its parent's menu item. The name of the menu item will be the title of the node and its weight will be the node's sort order.
If you edit the parent of a node or its title, you can recreate an existing menu item by checking "Recreate Menu". This will set the menu item's parent to the new parent and the title to the new title. This is not done automatically on edit, so that you can maintain menu hierarchy separately from node hierarchy if desired.
If the node does not have a parent or its parent does not have a menu item, the new menu item will be a child of the default menu item set in the Node Hierarchy settings.
Use the green arrow links on the Children tab of the parent node to rearrange child nodes. This will also update the order of any generated menu items as long as they have not been moved from their original location.
Node Hierarchy integrates with Pathauto to create hierarchical urls. There are two tokens provided to Pathauto 1.x by Node Hierarchy:
[hierarchypath]: This is the path of the node's parent.
[fullhierarchypath]: This is the path to the node including the node's own name. You can use this token on its own to create hierarchical urls for your nodes. This token is the same as [title] for nodes which do not have a parent.
Node Hierarchy integrates with token (and therefore Pathauto 2.x and others). For a description of available tokens see the Pathauto setting screen (or any other token list).
For Pathauto, the recommended token to use is [fullhierarchypath] as it will reflect any changes you have made to the url of a nodes ancestors. For example, if you have a node called "our history" but you forgot automatically generated urls and create the path alias 'history' for that node, its children will have the automatically generated paths 'history/xxx' instead of 'our-history/xxx'.
To enable views integration, turn on the Node Hierarchy Views module. With this module turned on, you will also be able to embed a view of a node's children on that node's page. Node hierarchy integrates with Views to provide the following:
Arguments
Parent Node Id - Takes a node id and returns only nodes which are children of that node. Used to provide lists of children for a given node.
Fields
Sort Order - The numerical sort order of a child node.
Actions - A set of actions to manipulate child nodes. Should only be used in views accessible by Administrators.
Sort Fields
Sort Order - Use this to sort child nodes by their Node Hierarchy sort order.
Node Access integration has been removed from Version 6, as the nodeaccess module has not been updated to 6 at the time of this writing.
This page is for helpful code examples that others may also find useful when working with Node Hierarchy. Please add examples as comments -