andriansandi
andriansandi

Reputation: 89

Modifying HTML output on Main Menu Drupal 7

I've developing my own theme and I'm experiencing problem to generate menu link with my own class, here's my menus supposed to be:

  <ul class="dropdown">
    <li class="first current-menu-item menu-item-home menu-gray">
            <a href="index-2.html"><span>HOME</span></a>
    </li>
    <li class="menu-red">
            <a href="2cols-sidebar-right.html"><span>Fashion</span></a>
    </li>
    <li class="menu-orange">
            <a href="2cols-sidebar-right.html"><span>Design</span></a>
    </li>
  </ul>

There's class "menu-red" or "menu-orange" will be different color on css. And this is how I print the main menus on template:

<?php
if ($main_menu):
       print theme('links__system_main_menu', 
                     array(
                          'links'          => $main_menu, 
                          'attributes'     => array(
                                                 'id' => 'main-menu', 
                                                 'class' => 'dropdown'
                                              )
                      )
                   ); 
endif;
?>

I've tried to override the links__system_main_menu function with my own on template.php but still no luck.

Thanks for helping.

Regards,

@andriansandi

Upvotes: 2

Views: 6292

Answers (2)

andriansandi
andriansandi

Reputation: 89

I'm got my answer from http://drupal.org/node/1033442#comment-5076932

Here:

function mytheme_links__system_main_menu($variables) {
  $html = "<div>\n";
  $html .= "  <ul>\n";  
  foreach ($variables['links'] as $link) {
    $html .= "<li>".l($link['title'], $link['path'], $link)."</li>";
  }
  $html .= "  </ul>\n";
  $html .= "</div>\n";

  return $html;
}

Upvotes: 1

Dragos Rizescu
Dragos Rizescu

Reputation: 3488

This is how I do it.

function YOURTHEME_menu_tree($variables) {
  return '<ul class="dropdown">' . $variables['tree'] . '</ul>';
}

Upvotes: 0

Related Questions