Hi there,
I’m struggling with the following. Subpages of a menu item.
I made this menu:
<?php
// main menu items
$items = $pages->listed();
// only show the menu if items are available
if($items->isNotEmpty()):
?>
<div class="menu-button menu-open"><i class="open-icon ion-android-menu"></i><i class="close-icon ion-android-close"></i></div>
<ul class="flexnav standard dark with-js opacity lg-screen" data-breakpoint="800">
<?php foreach($items as $item): ?>
<li class="item-with-ul <?php e($item->isOpen(), 'active') ?>">
<a href="<?= $item->url() ?>"><?= $item->title()->html() ?></a>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
Now I also want to show the subpages (children) of the menu. But: I don’t want to show all the blogpost under the parent ‘Blog’.
I know I have to use the nested menu:
<?php
// nested menu
$items = $pages->listed();
// only show the menu if items are available
if($items->isNotEmpty()):
?>
<nav>
<ul>
<?php foreach($items as $item): ?>
<li>
<a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><?= $item->title()->html() ?></a>
<?php
// get all children for the current menu item
$children = $item->children()->listed();
// display the submenu if children are available
if($children->isNotEmpty()):
?>
<ul>
<?php foreach($children as $child): ?>
<li><a<?php e($child->isOpen(), ' class="active"') ?> href="<?= $child->url() ?>"><?= $child->title()->html() ?></a></li>
<?php endforeach ?>
</ul>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
</nav>
<?php endif ?>
How can I decide which children I want to show. For example: Show children except for the blog and shop.
Thanks!