|
<!-- NAV BAR --> |
|
<div class="primary-menu__wrapper"> |
|
<div class="primary-menu"> |
|
<nav class="nav" role="navigation"> |
|
<ul> |
|
<?php $locations = get_nav_menu_locations(); |
|
|
|
// if there's a location for the primary menu |
|
if ( isset( $locations['primary-menu']) ) { |
|
$menu = get_term( $locations['primary-menu'], 'nav_menu'); |
|
|
|
// if there are items in the primary menu |
|
if ( $items = wp_get_nav_menu_items( $menu->name ) ) { |
|
|
|
// loop through all menu items to display their content |
|
foreach ( $items as $item ) { |
|
|
|
// if the current item is not a top level item, skip it |
|
if ($item->menu_item_parent != 0) { |
|
continue; |
|
} |
|
|
|
// get the ID of the current nav item |
|
$curNavItemID = $item->ID; |
|
|
|
// get the custom classes for the item |
|
// (determined within the WordPress Appearance > Menu section) |
|
$classList = implode(" ", $item->classes); |
|
echo "<li class=\"{$classList}\">"; |
|
echo "<a href=\"{$item->url}\">{$item->title}</a>"; |
|
|
|
// build the mega-menu |
|
// if 'mega-menu' exists within the class |
|
if ( in_array('has-mega-menu', $item->classes)) { ?> |
|
<div class="mega-menu__wrapper js-mega-menu"> |
|
<div class="mega-menu"> |
|
|
|
<div class="mega-menu__content"> |
|
<h2><?= $item->post_title; ?></h2> |
|
<p><?= $item->description; ?></p> |
|
<a href="<?= $item->url; ?>" class="learn-more">Learn More</a> |
|
</div> |
|
|
|
<div class="mega-menu__subnav"> |
|
<nav> |
|
<ul class="subnav"> |
|
<?php // cycle through the menu items and get the subnav |
|
foreach ( $items as $subnav) { |
|
if ( $subnav->menu_item_parent == $curNavItemID) { |
|
echo "<li><a href=\"{$subnav->url}\">{$subnav->title}</a>"; |
|
} |
|
} ?> |
|
</ul> |
|
</nav> |
|
</div> |
|
|
|
|
|
</div> |
|
</div> |
|
<?php } |
|
|
|
// if this is the search bar |
|
if ( in_array('nav-search', $item->classes) ) { ?> |
|
<div class="search-bar__wrapper"> |
|
<div class="search-bar"> |
|
<div class="search-bar__form"> |
|
<form> |
|
<input type="text" name="s" placeholder="Keywords" /> |
|
<button type="button" role="submit" name="Search">Search</button> |
|
</form> |
|
<a href="#" class="js-close-search search-bar__close"><svg role="img" class="icon"><use xlink:href="<?php bloginfo('template_url'); ?>/assets/dist/img/svg.svg#close"></use></svg></a> |
|
</div> <!-- /.search-bar__form --> |
|
</div><!-- /.search-bar --> |
|
</div><!-- /.search-bar__wrapper --> |
|
<?php } |
|
echo '</li>'; |
|
|
|
} |
|
} |
|
} ?> |
|
</ul> |
|
<?php //nationsu_primary_nav(); ?> |
|
</nav> |
|
</div><!-- /.primary-menu --> |
|
</div> <!-- /.primary-menu__wrapper --> |
I know this is kind of old but I had a random question if you had any idea how to bring in a 3rd level if the subnav has children.