/** * Build tree item * * Creates adjacency list based on group (id or slug) and shows leafs related only to current item * * @param mixed $group Group id or slug * @param int $item_id Current item id * @param array $attributes Any attributes * @param array &$tree Tree array * @param array &$in_array Output tree array * * @return string */ function build_tree_item($group, $item_id, $attributes = array(), &$tree = NULL, &$in_array = array()) { if (empty($tree)) { $CI =& get_instance(); $CI->load->library('adjacency_list'); $tree = $CI->adjacency_list->get_all($group); } if (!empty($tree)) { foreach ($tree as &$leaf) { if ($item_id === (int) $leaf['id']) { array_push($in_array, $leaf['id']); build_tree_item($group, (int) $leaf['parent_id'], $attributes, $tree, $in_array); } } $tree = parse_children($tree); $in_array = array_reverse($in_array); return format_tree($tree, $in_array, $attributes); } return ''; }
<ul> <?php echo build_tree_item('languages', 4); ?> </ul> </div> <div class="span8"> <pre><code> <ol> <?php echo build_tree_item('languages', 4, array('sub_start_tag' => '<ol>', 'sub_end_tag' => '</ol>')); ?> </ol> </code></pre> <ol> <?php echo build_tree_item('languages', 4, array('sub_start_tag' => '<ol>', 'sub_end_tag' => '</ol>')); ?> </ol> </div> </div> <div class="row"> <div class="span4"> <pre><code> <ul class="breadcrumb"> <?php echo build_breadcrumb('languages', 4); ?> </ul> </code></pre> <ul class="breadcrumb"> <?php echo build_breadcrumb('languages', 4); ?>