Hi,

I want to add a different div to the second level menu in drupal 7.
I want it to show like this in main menu

<div id="navigation">
        <ul id="menu">
               <li>Menu 1</li>
               <li>Menu 2</li>
               <li>Menu 3
                     <div id="dd">
                          <ul id="menu">
                                <li>Menu level 2-1</li>
                                <li>Menu level 2-2</li>
                          </ul>
                      </div>
               </li>
         </ul>
</div>

Currently am using this method but i don't prefer it because it uses global. I want to target main menu only.

function themename_menu_tree($variables) {
    if ($GLOBALS['custom_variables']['main-menu']['active'] ) {
        if ($GLOBALS['custom_variables']['main-menu']['level'] == 0) {
            $GLOBALS['custom_variables']['main-menu']['active'] = false;
            return '<ul class="menu" id="top">' . $variables['tree'] . '</ul>';
        } else {
            $GLOBALS['custom_variables']['main-menu']['level'] -= 1;
        }
    }
   
    return '<div class="dd"><ul class="menu">' . $variables['tree'] . '</ul></div>';
}


function themename_menu_link($variables) {

    $element = $variables['element'];
    $sub_menu = '';
   
    //menu principal
    if ($element['#theme'] ==  'menu_link__main-menu') {
        if (!isset($GLOBALS['custom_variables']['main-menu'])) {
            $GLOBALS['custom_variables']['main-menu']['level'] =  0;
            $GLOBALS['custom_variables']['main-menu']['active'] =  true;
        }
       
        if ($element['#below']) {
            $GLOBALS['custom_variables']['main-menu']['level'] += 1;
        }
    }
     
   
  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

Any idea?

Comments

emnzava’s picture

Any idea pls?

----------- *** ------------
The Only Easy Day Was Yesterday..!!!!

ishmael-sanchez’s picture

Can you just add the div using jQuery .wrap or .append functions?

emnzava’s picture

Hello Ishmael,

Can you point me to a link or tutorial where i can read the "HOW TO"?
I am a newbie to jQuery.

Thanx in advance...

----------- *** ------------
The Only Easy Day Was Yesterday..!!!!

ishmael-sanchez’s picture

jQuery .wrapInner(). Add a line in your theme info file for the script then create a scripts.js file in your theme and add the jQuery code. See more about the process at JavaScript and jQuery