Selectbox Menu with Subpages


i used the selectbox menu code from on my page.

But now i get only the main entries of the menu, but i want to add the subpages too.

How can i do that?

Thanks in advance :smile:


Try this …

  // main menu items
  $items = $pages->visible();

  // only show the menu if items are available

  <select onchange="window.location.href = this.value">
    <?php foreach($items as $item): ?>
    <option value="<?php echo $item->url() ?>"<?php e($item->isOpen(), ' selected="selected"') ?>><?php echo $item->title()->html() ?></option>

      <?php // check for visible subpages ?>
      <?php if($item->hasVisibleChildren()): ?>
        <?php foreach($item->children()->visible() as $subitem): ?>
          <option value="<?php echo $subitem->url() ?>"<?php e($subitem->isOpen(), ' selected="selected"') ?>>- <?php echo $subitem->title()->html() ?></option>
        <?php endforeach ?>
      <?php endif ?>

    <?php endforeach ?>
<?php endif ?>

That worked great @flokosiol - thank you!

But one more thing… One of my Main Pages is a Blog! I don’t want to see all the blog entries in the menu, so i need to exclude “blog” from displaying its subpages. All the other Main Pages should display their subpages.

EDIT: Fount this Hiding all subpages of a page from the menu and it worked great :smile:
Thanks again :smile:


It would be nice, if you could change the category of your topic to SOLVED. Thanks.