Guest User

Untitled

a guest
Mar 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.04 KB | None | 0 0
  1. <?php
  2. $locations = get_nav_menu_locations();
  3. $menu = get_term( $locations['primary-menu'], 'nav_menu');
  4. if ( $posts = wp_get_nav_menu_items( $menu->name ) ) {
  5.  
  6. # initialize the menu structure
  7. $menu = []; # the menu structure
  8. $byId = []; # menu ID-table (temporary)
  9.  
  10. # build the menu (hierarchy) from flat $rows traversable
  11. foreach ($posts as $row) {
  12. # map row to local ID variables
  13. $id = $row->ID;
  14. $parentId = $row->menu_item_parent;
  15.  
  16. # build the entry
  17. $entry['post'] = $row;
  18. # init submenus for the entry
  19. $entry['submenus'] = &$byId[$id]['submenus']; # [1]
  20.  
  21. # register the entry in the menu structure
  22. if (null === $parentId || 0 == $parentId) {
  23. # special case that an entry has no parent
  24. $menu[] = &$entry;
  25. } else {
  26. # second special case that an entry has a parent
  27. $byId[$parentId]['submenus'][] = &$entry;
  28. }
  29.  
  30. # register the entry as well in the menu ID-table
  31. $byId[$id] = &$entry;
  32.  
  33. # unset foreach (loop) entry alias
  34. unset($entry);
  35. }
  36. //print_r($menu);
  37. }
  38.  
  39. function print_classes($classes) {
  40. $css_classes = null;
  41. if($classes) {
  42. foreach($classes as $class) {
  43. echo $class . " ";
  44. }
  45.  
  46. }
  47. }
  48.  
  49. function print_product_info($product, $active) {
  50.  
  51. $is_accessory = is_object_in_term( $product->object_id, 'product_type', 'accessories' );
  52.  
  53. $i = rand(1,100);
  54.  
  55. $image = get_field('menu_thumbnail', $product->object_id);
  56.  
  57. if($is_accessory) {}
  58.  
  59. echo "<a href='$product->url' title='$product->title'>";
  60. if(!$is_accessory)
  61. echo "<div class='title'><h3>$product->title</h3></div>";
  62. echo "<div><img src='{$image['url']}' height='168' width='auto' /></div>";
  63. if($is_accessory)
  64. echo "<div class='product-title'>$product->title</div>";
  65. echo "</a>";
  66. if(!$is_accessory) {
  67. echo "<div class='prod-info-wrapper' $active >";
  68. the_product_specifications($product->object_id);
  69. //echo "<span class='tail'></span></div><!--prod info-->";
  70. }
  71. }
  72.  
  73. function print_menu($id) {
  74. $label = get_field('menu_label', $id);
  75. $description = get_field('menu_description', $id);
  76. $image = get_field('menu_image', $id);
  77.  
  78. echo "<div class='menu-block'>";
  79. echo "<div class='menu-block-left'>";
  80. if($label) {
  81. echo "<div class='title'>$label</div>";
  82. }
  83. if($description) {
  84. echo "<div>$description</div>";
  85. }
  86. echo "</div><!-- END item-left-->";
  87. echo "<div class='menu-block-right'>";
  88. if(1) {
  89. if($image) {
  90. echo "<div><div style=\"background-image: url('{$image['url']}'); padding-bottom: 80%; background-size: cover; \"><!-- img src='{$image['url']}' --></div></div>";
  91. }
  92. }
  93. echo "</div><!-- END item-right-->";
  94. echo "<div>";
  95. }
  96.  
  97. ?>
  98.  
  99. <!--div class="title-bar" data-responsive-toggle="example-menu" data-hide-for="medium">
  100. <button class="menu-icon" type="button" data-toggle="example-menu"></button>
  101. <div class="title-bar-title">Menu</div>
  102. </div -->
  103. <div class="primary-menu-wrapper" id="example-menu">
  104. <div class="primary-menu">
  105. <nav class="nav" role="nav">
  106. <ul class="menu primary-items align-center">
  107. <?php foreach( $menu as $menu_item ) : ?>
  108. <li>
  109. <a href="#"><?php echo $menu_item['post']->title; ?></a>
  110. <?php if ( count($menu_item['submenus']) ) : ?>
  111. <div class="mega-menu-wrapper">
  112. <div class="mega-menu <?php print_classes($menu_item['post']->classes); ?>">
  113. <div class="secondary-items-wrapper">
  114. <ul class="secondary-items">
  115. <?php foreach($menu_item['submenus'] as $i=>$secondary_item ) : $active = ($i == 0) ? 'data-default' : ''; ?>
  116. <li <?php echo $active; ?>>
  117. <a href="<?php echo $secondary_item['post']->url ?>" title="<?php echo $secondary_item['post']->title; ?>">
  118. <?php if( ! in_array('menu-story', $menu_item['post']->classes) ) {
  119. echo $secondary_item['post']->title . "</a>";
  120. } ?>
  121. <div class="tertiary-items-wrapper" <?php echo $active; ?>>
  122. <?php if( in_array('submenu-aceesories', $secondary_item['post']->classes) ) {
  123. echo "<h3 class='section-header'>accessories</h3>";
  124. } ?>
  125. <ul class="tertiary-items <?php print_classes($secondary_item['post']->classes); ?>" >
  126. <?php if( count($secondary_item['submenus']) > 0 ) {
  127. foreach ($secondary_item['submenus'] as $tertiary_item) : $tertiary_item = $tertiary_item['post'];
  128. $product_type = get_the_terms( $tertiary_item->object_id, 'product_type')[0];
  129. echo "<li>";
  130. print_product_info($tertiary_item, $active);
  131. echo "</li>";
  132. endforeach;
  133. if( ($product_type->slug == 'booster-seats' || $product_type->slug == 'convertible-seats') ) {
  134. the_category_specifications($product_type);
  135. }
  136. } else {
  137. echo "<li>";
  138. print_menu($secondary_item['post']->object_id);
  139. echo "</li>";
  140. } ?>
  141. </ul>
  142. </div>
  143. <?php if( in_array('menu-story', $menu_item['post']->classes) ) {
  144. echo "</a>";
  145. }?>
  146. </li>
  147. <?php endforeach; ?>
  148. </ul>
  149. </div>
  150. </div>
  151. </div>
  152. <?php endif; ?>
  153. </li>
  154. <?php endforeach; ?>
  155. </ul>
  156. </nav>
  157. </div>
  158. </div>
Add Comment
Please, Sign In to add comment