Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $locations = get_nav_menu_locations();
- $menu = get_term( $locations['primary-menu'], 'nav_menu');
- if ( $posts = wp_get_nav_menu_items( $menu->name ) ) {
- # initialize the menu structure
- $menu = []; # the menu structure
- $byId = []; # menu ID-table (temporary)
- # build the menu (hierarchy) from flat $rows traversable
- foreach ($posts as $row) {
- # map row to local ID variables
- $id = $row->ID;
- $parentId = $row->menu_item_parent;
- # build the entry
- $entry['post'] = $row;
- # init submenus for the entry
- $entry['submenus'] = &$byId[$id]['submenus']; # [1]
- # register the entry in the menu structure
- if (null === $parentId || 0 == $parentId) {
- # special case that an entry has no parent
- $menu[] = &$entry;
- } else {
- # second special case that an entry has a parent
- $byId[$parentId]['submenus'][] = &$entry;
- }
- # register the entry as well in the menu ID-table
- $byId[$id] = &$entry;
- # unset foreach (loop) entry alias
- unset($entry);
- }
- //print_r($menu);
- }
- function print_classes($classes) {
- $css_classes = null;
- if($classes) {
- foreach($classes as $class) {
- echo $class . " ";
- }
- }
- }
- function print_product_info($product, $active) {
- $is_accessory = is_object_in_term( $product->object_id, 'product_type', 'accessories' );
- $i = rand(1,100);
- $image = get_field('menu_thumbnail', $product->object_id);
- if($is_accessory) {}
- echo "<a href='$product->url' title='$product->title'>";
- if(!$is_accessory)
- echo "<div class='title'><h3>$product->title</h3></div>";
- echo "<div><img src='{$image['url']}' height='168' width='auto' /></div>";
- if($is_accessory)
- echo "<div class='product-title'>$product->title</div>";
- echo "</a>";
- if(!$is_accessory) {
- echo "<div class='prod-info-wrapper' $active >";
- the_product_specifications($product->object_id);
- //echo "<span class='tail'></span></div><!--prod info-->";
- }
- }
- function print_menu($id) {
- $label = get_field('menu_label', $id);
- $description = get_field('menu_description', $id);
- $image = get_field('menu_image', $id);
- echo "<div class='menu-block'>";
- echo "<div class='menu-block-left'>";
- if($label) {
- echo "<div class='title'>$label</div>";
- }
- if($description) {
- echo "<div>$description</div>";
- }
- echo "</div><!-- END item-left-->";
- echo "<div class='menu-block-right'>";
- if(1) {
- if($image) {
- echo "<div><div style=\"background-image: url('{$image['url']}'); padding-bottom: 80%; background-size: cover; \"><!-- img src='{$image['url']}' --></div></div>";
- }
- }
- echo "</div><!-- END item-right-->";
- echo "<div>";
- }
- ?>
- <!--div class="title-bar" data-responsive-toggle="example-menu" data-hide-for="medium">
- <button class="menu-icon" type="button" data-toggle="example-menu"></button>
- <div class="title-bar-title">Menu</div>
- </div -->
- <div class="primary-menu-wrapper" id="example-menu">
- <div class="primary-menu">
- <nav class="nav" role="nav">
- <ul class="menu primary-items align-center">
- <?php foreach( $menu as $menu_item ) : ?>
- <li>
- <a href="#"><?php echo $menu_item['post']->title; ?></a>
- <?php if ( count($menu_item['submenus']) ) : ?>
- <div class="mega-menu-wrapper">
- <div class="mega-menu <?php print_classes($menu_item['post']->classes); ?>">
- <div class="secondary-items-wrapper">
- <ul class="secondary-items">
- <?php foreach($menu_item['submenus'] as $i=>$secondary_item ) : $active = ($i == 0) ? 'data-default' : ''; ?>
- <li <?php echo $active; ?>>
- <a href="<?php echo $secondary_item['post']->url ?>" title="<?php echo $secondary_item['post']->title; ?>">
- <?php if( ! in_array('menu-story', $menu_item['post']->classes) ) {
- echo $secondary_item['post']->title . "</a>";
- } ?>
- <div class="tertiary-items-wrapper" <?php echo $active; ?>>
- <?php if( in_array('submenu-aceesories', $secondary_item['post']->classes) ) {
- echo "<h3 class='section-header'>accessories</h3>";
- } ?>
- <ul class="tertiary-items <?php print_classes($secondary_item['post']->classes); ?>" >
- <?php if( count($secondary_item['submenus']) > 0 ) {
- foreach ($secondary_item['submenus'] as $tertiary_item) : $tertiary_item = $tertiary_item['post'];
- $product_type = get_the_terms( $tertiary_item->object_id, 'product_type')[0];
- echo "<li>";
- print_product_info($tertiary_item, $active);
- echo "</li>";
- endforeach;
- if( ($product_type->slug == 'booster-seats' || $product_type->slug == 'convertible-seats') ) {
- the_category_specifications($product_type);
- }
- } else {
- echo "<li>";
- print_menu($secondary_item['post']->object_id);
- echo "</li>";
- } ?>
- </ul>
- </div>
- <?php if( in_array('menu-story', $menu_item['post']->classes) ) {
- echo "</a>";
- }?>
- </li>
- <?php endforeach; ?>
- </ul>
- </div>
- </div>
- </div>
- <?php endif; ?>
- </li>
- <?php endforeach; ?>
- </ul>
- </nav>
- </div>
- </div>
Add Comment
Please, Sign In to add comment