/**
* Navigation
*/
class Navigation {
/**
* Construct
*/
public function __construct() {
add_filter( 'walker_nav_menu_start_el', array( $this, 'mega_sub_menu' ), 10, 4 );
}
/**
* Mega sub menu
*/
public function mega_sub_menu( $item_output, $item, $depth, $args ) {
if ( ! in_array( 'v-has-mega-sub-menu', $item->classes, true ) ) {
return $item_output;
}
ob_start();
get_template_part( 'templates/mega-sub-menu' );
$mega_sub_menu_html = ob_get_clean();
// Append after <a> element of the menu item targeted
$item_output .= $mega_sub_menu_html;
return $item_output;
}
}
We use this template part:
<div class="v-mega-sub-menu">
<div class="v-mega-sub-menu__container">
<?php
$query = new WP_Query(
array(
'post_type' => 'location',
'posts_per_page' => 50,
'no_found_rows' => true,
)
);
if ( $query->have_posts() ) : ?>
<ul>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php
wp_reset_postdata();
endif;
?>
</div>
</div>