Skip children of page in navigation

You babe, thanks so much! I know what I was doing wrong now.

On a similar topic, do you know how I’d go about hiding child items from a dropdown for a particular page (so in this case I’ve setup the testimonials as children but I don’t want them to be clickable in the menu). My code is below, please let me know if you want me to start a new topic.

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <?php foreach($pages->visible() as $item): ?>
        <li class="menu-item<?= r($item->isOpen(), ' is-active')?><?php e($item->hasChildren(), ' dropdown')?>">
          <a id="<?= $item->title()->html() ?>" href="<?= $item->url() ?>" <?php e($item->hasChildren(), ' class="dropdown-toggle disabled" data-toggle="dropdown"')?>><?= $item->title()->html() ?></a>
            <?php if($item->hasChildren()): ?>
              <ul class="dropdown-menu" role="menu">
                <?php foreach($item->children() as $child): ?>
                  <li><a href="<?= $child->url() ?>"><?php echo $child->title() ?></a></li>
                <?php endforeach ?>
              </ul>
            <?php endif ?>
        </li>
        <?php endforeach ?>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">GET IN TOUCH</a></li>
      </ul>
    </div>
  </div>
</nav>

<script type="text/javascript">
$(document).ready(function(){
    $(".dropdown").hover(
        function() {
            $('.dropdown-menu', this).not('.in .dropdown-menu').stop( true, true ).slideDown("fast");
            $(this).toggleClass('open');
        },
        function() {
            $('.dropdown-menu', this).not('.in .dropdown-menu').stop( true, true ).slideUp("fast");
            $(this).toggleClass('open');
        }
    );
});
</script>

In addition to checking if the page has children, also check if it uses a particular template, in this case probably “testimonials”.

<?php e($item->hasChildren() && $item->intendedTemplate() != 'testimonials', ' dropdown')?>
1 Like

Thanks, incredible support!

1 Like