I've a menu like this-

<!-- Main Menu -->
<ul class="nav sf-menu clearfix">
    <li><a href="about.html">About Us</a></li>
    <li><a href="index.html">Artists</a><em></em></li>
    <li class="sub-menu"><a href="index.html">Works</a><em></em>
            <li><a href="#">Dolore ipsu</a></li>
            <li class="sub-menu"><a href="#">Consecte</a>
                    <li><a href="#">Dolore ipsu</a></li>
                    <li><a href="#">Consecte</a></li>
                    <li><a href="#">Elit Conseq</a></li>
            <li><a href="#">Elit Conseq</a></li>
    <li><a href="index.html">Blog</a><em></em></li>
    <li><a href="contact.html">Contacts</a><em></em></li>
<!-- End Main Menu -->

There's a whole section of CSS style information for that plain HTML section. I've tried to add the site's Main Menu to page.tpl but it isn't showing up When I add the following PHP code-

    $menu = menu_navigation_links('menu-main-page');
    print theme('links__menu_main_page', array('links' => $menu));

What am I doing wrong here?

Also when it DOES show up, I'd like to which elements are printed exactly when trying to include the menu and how to assign the generated ul / li to some classes, as required for the CSS to apply style to those elements?

1 Answer 1


In Bartik, menu is added like that:

    <?php if ($main_menu): ?>
      <div id="main-menu" class="navigation">
        <?php print theme('links__system_main_menu', array(
          'links' => $main_menu,
          'attributes' => array(
            'id' => 'main-menu-links',
            'class' => array('links', 'clearfix'),
          'heading' => array(
            'text' => t('Main menu'),
            'level' => 'h2',
            'class' => array('element-invisible'),
        )); ?>
      </div> <!-- /#main-menu -->
    <?php endif; ?>

Except the fact that $main_menu was not provided in page.tpl.php nor in template.php, apparently created by menu module, it looks like your code, just more elaborate. This indicates that either in menu_navigation_links or in theme you passed an argument that happens not to work. Except that it should be all right. Use dpr() or var_dump() to see which one fails.

If you need better control over your menus, I suggest using Menu block module to put them. This module allows you to treat menus or their parts as a blocks, so in your template all you need to do is to output proper region.

To get classes on menu items, you can simply use Menu attributes module:

The module currently allows you to set the following attributes for each menu item:

  • Id
  • Name
  • Target
  • Rel
  • Class
  • Style
  • Accesskey

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.