function emiglio_exhibit_builder_page_nav($exhibitPage = null, $currentPageId) { if (!$exhibitPage) { $exhibitPage = get_current_record('exhibit_page'); } $parents = array(); $currentPage = get_record_by_id('Exhibit Page', $currentPageId); while ($currentPage->parent_id) { $currentPage = $currentPage->getParent(); array_unshift($parents, $currentPage->id); } $class = ''; $class .= $exhibitPage->id == $currentPageId ? 'current' : ''; $parent = array_search($exhibitPage->id, $parents) !== false ? ' parent' : ''; $html = '<li class="' . $class . $parent . '">' . '<a href="' . exhibit_builder_exhibit_uri(get_current_record('exhibit'), $exhibitPage) . '">' . metadata($exhibitPage, 'title') . '</a>'; $children = $exhibitPage->getChildPages(); if ($children) { $html .= '<ul>'; foreach ($children as $child) { $html .= emiglio_exhibit_builder_page_nav($child, $currentPageId); release_object($child); } $html .= '</ul>'; } $html .= '</li>'; return $html; }
<nav id="exhibit-pages"> <ul> <?php $currentPageId = metadata('exhibit_page', 'id'); ?> <?php $currentPage = get_current_record('exhibit page'); ?> <?php set_exhibit_pages_for_loop_by_exhibit(); ?> <?php foreach (loop('exhibit_page') as $exhibitPage) { ?> <?php echo emiglio_exhibit_builder_page_nav($exhibitPage, $currentPageId); ?> <?php } ?> <?php set_current_record('exhibit page', $currentPage); ?> </ul> </nav> </div> <div id="exhibit-page-navigation"> <?php if ($prevLink = exhibit_builder_link_to_previous_page()) { ?>