Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

get_node_tree()

Description

This function returns a multidimensional array with hierarchy that reflects category tree field hierarchy, using parent and order_by fields

Parameters

ColumnTypeDefaultDescription
$parentId string "" - elements at top of tree do not have a value for "parent" field, so default value is empty string, otherwise it is the value of the parent element in tree
$nodes array array - node tree to parse and order

Return

array $tree - multidimension array containing nodes in correct hierarchical order

Location

include/node_functions.php lines 2045 to 2062

Definition

 
function get_node_tree($parentId "", array $nodes = array())
    {
    
$tree = array();
    foreach (
$nodes as $node
        {
        if(
$node["parent"] == $parentId)
            {
            
$children get_node_tree($node["ref"] , $nodes);
            if (
$children)
                {
                
uasort($children,"node_orderby_comparator"); 
                
$node["children"] = $children;
                }
            
$tree[] = $node;
            }
        }
    return 
$tree;
    }

This article was last updated 19th March 2024 07:05 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.