/** * Print the site tree as an HTML list with the current * context open as sub-lists up to the first-level children * of the current page. The currently active page will have * the class `current` and parents will have the class * `parent`. * * Usage: * * $n = new Navigation; * $path = $n->path ($page->id); * $path = ($path) ? $path : array (); * navigation_print_context ($n->tree, $path); */ function navigation_print_context($tree, $path) { echo '<ul>'; foreach ($tree as $item) { if ($item->attr->id == $path[count($path) - 1]) { echo '<li class="current">' . Link::make($item->attr->id, $item->data); if (isset($item->children)) { navigation_print_context($item->children, $path); } echo '</li>'; } elseif (in_array($item->attr->id, $path)) { echo '<li class="parent">' . Link::make($item->attr->id, $item->data); if (isset($item->children)) { navigation_print_context($item->children, $path); } echo '</li>'; } else { printf('<li><a href="/%s">%s</a></li>', $item->attr->id, $item->data); } } echo '</ul>'; }
<?php /** * Displays contextual navigation, opening and closing * sections based on the currently active page. Shows * All parents and children of the current page. */ $n = Link::nav (); $path = $n->path ($page->id); $path = ($path) ? $path : array (); require_once ('apps/navigation/lib/Functions.php'); if (conf ('I18n', 'multilingual')) { $section = $n->node ($i18n->language); if (is_array ($section->children)) { navigation_print_context ($section->children, $path); } } else { navigation_print_context ($n->tree, $path); }