YAMM3 mega menu and nav walker

Hi,

I’m digging the web with no result wanting to integrate YAMM3 into the roots. I’ve succesfully add yamm basic markup, which was clearly very simple but I can’t figure out next steps.

So, I want to achieve something like this:

WordPress menu layout

Parent
-itemA
—itemB
—itemB
-itemA
—itemB
—itemB

And YAMM3 result will be menu item (Parent) with two columns dropdown made by ‘itemA’ (colum title) with menu items below - ‘itemB’.

Parent
|----ItemA-----ItemA----|
|…|
|----ItemB-----ItemB-----|
|----ItemB-----ItemB-----|
|…|

I think my amazing ASCII drawing is understandable:)

As I presume I should add class=row below dropdown-menu, class=col- to the itemA and nest itemB in it.

But… I just don’t know where to start, continue and end not messing up beatiful roots walker.

I saw that one or two people here are asking about Yamm3 but there are no explenation how to make it. I can’t find any clue on the internet about YAMM3 and WordPress, it would be nice if someone can halp with it. I can’t be only stupid on this planet;)

Thanks in advance!

EDIT:
After I’ve added 'depth' => 3 I’m able to see sub-menu levels in page code, but they aren’t apear because they are wrapped in dropdown-menu. I’m playing with nav.php but I feel like hitting the wall.

1: Start by implementing git, with git you don´t have to be afraid of screwing up your theme.
2: Install Yamm3.
3: I would start looking in to the templates/header-top-navbar.php this is used to control the navbar.
4: Look at the examples and try to implement it with the template above.
5: You might have to do some changes in lib/nav.php and read up on walker nav menu, it controls the look and function of the menu in the roots theme.

Ask if you need more help, but do your homework as well :smiley:

I think my english isn’t good enough.

  1. I’m not afraid of project, but I don’t want to mess up roots nav walker. This exactly part of theme. I could probably done what I want with regular nav walker but this is not a plan.
  2. Done.
  3. Done.
  4. Problem here.
  5. Massive problem here.

Belive me or not. I’ve spend hours on this problem. I just don’t know what to do in this exact case. I’d rather need specific code for it, not ‘draw a circle and add rest of the head’ tutorial;)

1 Like

Are you running git? If you are running git you can mess around with the code as much as you want and then reset the code when ever you want. Look at the github.com and learn a little about version control before you continue. I would recommend you to do this before you continue implementing the menu. I think you will have to change the liv/nav.php to get YAMM3 working properly.

Really, @sten_e_winroth thanks for your efforts but this is completly irrelevant to my problem.

I know where I need to change but what I don’t know is how to change it.

So please, if you can’t help me with precise code I need to use, stop sending me to do homework and learning version control. Nevertheless thanks for trying!

1 Like

@l_dudzic Try this, I think it is a complete example.

And again, look up to earlier posts.

I want this exact roots nav walker with yamm.

I’m aware of different walkers, and I can make some, but I can’t get it with roots nav walker and this walker is just amazing with his clean links.

EDIT:
Please, anybody? I know it’s not a problem for you and I am struggle with it with no luck for days…

EDIT 2:
So I’ve added manually classes in wp menu managment but still my depth=2 or as I described it before itemB is wrapped in class=dropdown-menu this is last issue and menu will be working as expected. Please help me with this…

EDIT 3:
Adding

if ($element->is_dropdown && ($depth === 1)) { $element->classes[] = 'col-sm-4'; }

to the nav.php gave me needed columns in mega menu but still I can’t remove<ul class="dropdown-menu"> from depth=2.

EDIT 4:
After so much stuggle I finally did it:)

for future use:
function start_lvl(&$output, $depth, $args = array()) { $output .= ( $depth == 0 ) ? "\n<ul class=\"dropdown-menu row\">\n" : "\n<ul class=\"ItemB\">\n";}

4 Likes

Awesome share! @l_dudzic

Not using this currently but will be useful for future references. Thanks for this!

This one is amazing!!! http://wordpress.stackexchange.com/questions/150010/mega-menu-walker

Great work, but I can’t see how it is related to this topic?

And it has ugly output:

<li id="menu-item-4" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-4">

Compared to yamm and roots walker:

<li class="col-sm-4 menu-col menu-sprawnosc-energetyczna">

Ok let me explain more…This is a Walker Class that allows you to have a highly advanced Mega style Menu in WordPress. To see an example output of my menu view this screenshot here http://i.imgur.com/qeC9hav.png http://i.imgur.com/qeC9hav.png Ok now to explain how it works a little more. To add a NEW Column of menu items, in the WordPress Menu admin, you put a CSS Class named break at each menu item that you want to start a new column with. Now to add the Badge that you see in my example screenshot above, the orange background Badge that reads “Popular” you ad a CSS Class called popular-badge to the menu item in the menu admin! Now lastly to go even further with this, we are able to add a Widgetized are to our menu as well!!! To do this, we pick a menu that has a sub-menu in the menu admin, and in this menu-submenu we add a CSS Class named widget. What this does is adds a widgetized area to the menu…we can then go to the WordPress admin panel widget area and there will be a new “widget area” in which we can add ANY widget we want and it will show up in our Menu. NOw thjat is a Walker Menu Class on Steroids if you ask me!!

Great @jasondavis, I really don’t know why you explain it. It was pretty clear reading stack.

This topic was created to solve certain problem - yamm3 with roots nav walker. That’s all. This is why I can’t underestand why are you pasting your discovery in here.

I explain it because even though it is not your “YAMM3” menu, it is still in the same class of Mega Style Menu’s. THe bottom line is what I posted is a 100% working and you can learn a lot from it’s code, even how to fix your YAMM3 problems. Sorry that you don’t see the value but I am positive that it will help someone else that is trying to work with Mega Style Menu’s… I’m sorry to hear that it doesn’t help your situation

1 Like

Everything is ok. But my question is why here?

If you can take a minute and read the whole topic you can clearly see that the problem is solved in the way it meant to be. Everything is working as expected with preservation of roots nav walker!

Your solution is wordpress general related and not roots. Thanks for posting it, but I don’t think it is a good place.

YAMM3 isn’t mine.

2 Likes

Any chance you could post your complete solution? I’m working on the same issue now.

…Making YAMM megamenu work within the roots walker paradigm.

init/nav.php

<?php
    /**
     * Cleaner walker for wp_nav_menu()
     *
     * Walker_Nav_Menu (WordPress default) example output:
     *   <li id="menu-item-8" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8"><a href="/">Home</a></li>
     *   <li id="menu-item-9" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-9"><a href="/sample-page/">Sample Page</a></l
     *
     * Roots_Nav_Walker example output:
     *   <li class="menu-home"><a href="/">Home</a></li>
     *   <li class="menu-sample-page"><a href="/sample-page/">Sample Page</a></li>
     */
    class Roots_Nav_Walker extends Walker_Nav_Menu {
      function check_current($classes) {
        return preg_match('/(current[-_])|active|dropdown/', $classes);
      }
    
      function start_lvl(&$output, $depth, $args = array()) {
        
          
          
          $output .= ( $depth == 0 ) ? "\n<ul class=\"dropdown-menu\">\n"."\n<div class=\"yamm-content\">\n"."\n<div class=\"row\">\n"  : "\n<ul class=\"elementy-ul yamm-fw\">\n";
        
               
      }
         
    
      function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
        $item_html = '';
        parent::start_el($item_html, $item, $depth, $args);
    
        if ($item->is_dropdown && ($depth === 0)) {
          $item_html = str_replace('<a', '<a class="dropdown-toggle" data-toggle="dropdown" data-target="#"', $item_html);
          $item_html = str_replace('</a>', ' <b class="caret"></b></a>', $item_html);
        }
          
           elseif ($item && ($depth === 2)) {
          $item_html = str_replace('<a', '<div', $item_html);
          $item_html = str_replace('</a>', ' </div>', $item_html);
        }
       
        elseif (stristr($item_html, 'li class="divider')) {
          $item_html = preg_replace('/<a[^>]*>.*?<\/a>/iU', '', $item_html);
        }
        elseif (stristr($item_html, 'li class="dropdown-header')) {
          $item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '$1', $item_html);
        }
    
        $item_html = apply_filters('roots_wp_nav_menu_item', $item_html);
        $output .= $item_html;
      }   
        
    
      function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) {
          
     $element->is_dropdown = ((!empty($children_elements[$element->ID]) && (($depth + 1) < $max_depth || ($max_depth === 0))));
        if ($element->is_dropdown) {
          $element->classes[] = 'dropdown'; 
            
            
      }
        if ($element && ($depth === 1)) {
            $element->classes[] = 'col-sm-4 menu-col';  
        }  
          
      parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
      }
            
    }
    
    /**
     * Remove the id="" on nav menu items
     * Return 'menu-slug' for nav menu classes
     */
    function roots_nav_menu_css_class($classes, $item) {
      $slug = sanitize_title($item->title);
      $classes = preg_replace('/(current(-menu-|[-_]page[-_])(item|parent|ancestor))/', 'active', $classes);
      $classes = preg_replace('/^((menu|page)[-_\w+]+)+/', '', $classes);
    
      $classes[] = 'menu-' . $slug;
    
      $classes = array_unique($classes);
    
      return array_filter($classes, 'is_element_empty');
    }
    add_filter('nav_menu_css_class', 'roots_nav_menu_css_class', 10, 2);
    add_filter('nav_menu_item_id', '__return_null');
    
    /**
     * Clean up wp_nav_menu_args
     *
     * Remove the container
     * Use Roots_Nav_Walker() by default
     */
    function roots_nav_menu_args($args = '') {
      $roots_nav_menu_args['container'] = false;
    
      if (!$args['items_wrap']) {
        $roots_nav_menu_args['items_wrap'] = '<ul class="%2$s">%3$s</ul>';
      }
    
      if (current_theme_supports('bootstrap-top-navbar') && !$args['depth']) {
        $roots_nav_menu_args['depth'] = 3;
      }
    
      if (!$args['walker']) {
        $roots_nav_menu_args['walker'] = new Roots_Nav_Walker();
      }
    
      return array_merge($args, $roots_nav_menu_args);
    }
    add_filter('wp_nav_menu_args', 'roots_nav_menu_args');

and for header-top-navbar.php

 <?php
        if (has_nav_menu('primary_navigation')) :
          wp_nav_menu(array('theme_location' => 'primary_navigation',  'depth' => 3, 'menu_class' => 'nav navbar-nav navbar-left'));
        endif;
      ?>
2 Likes

hi,
there’s a way to put an image in the submenu item ?

thank you

Yes, just use plugin -> https://wordpress.org/plugins/menu-image/

thank you!
is just what I was looking for.

:smile: