OrganizedFellow Posted October 13, 2014 Share Posted October 13, 2014 Hiya gang! I'm using Foundation 5 for my CSS framework. I took the following code from Zurb Foundation 4 Site Profile. <div class="contain-to-grid"> <nav class="top-bar" data-topbar> <section class="top-bar-section"> <ul class="left"> <?php $homepage = $pages->get('/'); /** * Render items for placement in Foundation 'top-bar' recursive drop-down navigation * */ function renderTopNav(PageArray $items, array $options = array(), $level = 0) { $defaults = array( 'tree' => 2, // number of levels it should recurse into the tree 'dividers' => true, 'repeat' => true, // whether to repeat items with children as first item in their children nav ); $options = array_merge($defaults, $options); $divider = $options['dividers'] ? "<li class='divider'></li>" : ""; $page = wire('page'); $out = ''; foreach($items as $item) { $numChildren = $item->numChildren(true); if($level+1 > $options['tree'] || $item->id == 1) $numChildren = 0; $class = ''; if($numChildren) $class .= "has-dropdown "; if($page->id == $item->id) $class .= "current "; if(($item->id > 1 && $page->parents->has($item)) || $page->id == $item->id) $class .= "active "; if($class) $class = " class='" . trim($class) . "'"; $out .= "$divider<li$class><a href='$item->url'>$item->title</a>"; if($numChildren) { $out .= "<ul class='dropdown'>"; if($options['repeat']) $out .= "$divider<li><a href='$item->url'>$item->title</a></li>"; $out .= renderTopNav($item->children, $options, $level+1); $out .= "</ul>"; } $out .= "</li>"; } return $out; } ?> <?php echo renderTopNav($homepage->children->prepend($homepage)); ?> </ul> </section> </nav> </div> Here is what my tree looks like: It almost displays as expected, but the child pages of 'Testimonials' does not show in the drop menu. ONly the root shows Why not? I've even changed this to a larger number, but still ... no children. 'tree' => 2, // number of levels it should recurse into the tree Link to comment Share on other sites More sharing options...
kongondo Posted October 13, 2014 Share Posted October 13, 2014 Your code works for me...Are those child pages 'hidden' or 'unpublished'? Link to comment Share on other sites More sharing options...
OrganizedFellow Posted October 13, 2014 Author Share Posted October 13, 2014 Your code works for me...Are those child pages 'hidden' or 'unpublished'? All pages NOT hidden and published. Yes sir. Link to comment Share on other sites More sharing options...
remove Posted December 29, 2014 Share Posted December 29, 2014 @ OrganizedFellow: I know this is an older post but the code works. Did you still find problems with it or found any errors? I'am trying to build a foundation site and would like to use the navigation code. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now