<nav class="mega-menu"> <ul> <?php /* we grab all the data from our content region and assign it to a variable with a "skip-template" parameter set to "true". It will prevent from rendering the menu for now. */ $menu_custom = perch_content_custom('Mega Menu',array( 'skip-template' => true ), true); // lets go through every menu item foreach ($menu_custom as $key => $menuitem) { // for every item that has a url defined we output a usual link for our navigation */ if(isset($menuitem['navitemhref'])){ echo "<li><a class='mega-menu-link' href='" . $menuitem['navitemhref'] . "'>" . $menuitem['navitem'] . "</a></li>"; } else { // otherwise let's have a static label that will act as a drop down trigger echo "<li class='mega-menu-dropdown'><span class='mega-menu-link'>" . $menuitem['navitem'] . "</span><div class='mega-menu-col-wrapper'>"; // now let's run a loop through all of Perch Blocks and identify whether there is a column or a column item that we are dealing with foreach ($menuitem['_blocks'] as $key => $dropdownitem) { if(isset($dropdownitem['collabel'])) { // we also need to look out where column starts and finishes if($key !== 0) { echo "</ul></div><div class='mega-menu-col'><p class='mega-menu-link'>" . $dropdownitem['collabel'] . "</p> <ul>"; } else { echo "<div class='mega-menu-col'><p class='mega-menu-link'>" . $dropdownitem['collabel'] . "</p> <ul>"; } } else { echo "<li class='mega-menu-item'><a href='" . $dropdownitem['colitemhref'] . "'>" . $dropdownitem['colitem'] . "</a></li>"; } } echo "</div></li>"; } } ?> </ul> </nav>