Jump to content

foundation 5 navigation question


bwakad
 Share

Recommended Posts

I see in includes/navigation.php the following code. The code in bold is my problem.

In the menu - I want the parent page to be visible and clickable, but not it's childs of this menu item.

My page tree is

root

- menu item

- - child 1

- - child 2

childs can be more then 30 so it's not good to see those in the menu.

edit - the bold get's removed when using code tags... I was talking about this piece:

if($has_children && $child !== $root) {
                $class .= 'has-dropdown'; // sub level Foundation dropdown li class
                $childUrl = "#"; // stop parents being clickable
        } else {

function renderChildrenOf($pa, $root = null, $output = '', $level = 0) {
    if(!$root) $root = wire("pages")->get(1);
    $output = '';
    $level++;
    foreach($pa as $child) {
        $class = '';
        $has_children = count($child->children) ? true : false;
        if($has_children && $child !== $root) {
                $class .= 'has-dropdown'; // sub level Foundation dropdown li class
                $childUrl = "#"; // stop parents being clickable
        } else {
            $childUrl = $child->url; // if does not have children, then get the page url
        }
        // make the current page and only its first level parent have an active class
        if($child === wire("page")){
            $class .= ' active';
        } else if($level == 1 && $child !== $root){
            if($child === wire("page")->rootParent || wire("page")->parents->has($child)){
                $class .= ' active';
            }
        }
        $class = strlen($class) ? " class='".trim($class)."'" : '';    
        $output .= "<li$class><a href='$childUrl'>$child->title</a>";
        // If this child is itself a parent and not the root page, then render its children in their own menu too...
        if($has_children && $child !== $root) {
            $output .= renderChildrenOf($child->children, $root, $output, $level);
        }
        $output .= '</li>';
    }
    $outerclass = ($level == 1) ? "left" : 'dropdown';
    return "<ul class='$outerclass'>$output</ul>";
}
 
// bundle up the first level pages and prepend the root home page
$root = $pages->get(1);
$pa = $root->children;
$pa = $pa->prepend($root);
 
// Set the ball rolling...
echo renderChildrenOf($pa);
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...