5

I want to code a custom menu straight into page.tpl.php. The default theme uses

<?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; ?>

In Drupal 7 I've created a new menu called 'Footer menu'. How do I code that into my theme in the same way as the $main_menu is coded in the default theme?

  • Your custom menu will be available as a block, you can simply place that into footer region. This will save you some time and effort. – Fahad Ur Rehman Mar 15 '13 at 11:22
  • I understand that, however I want to have more control over the output like I would have in the example above – tommyf Mar 15 '13 at 11:27
5

Try this

<?php
 $menu = menu_navigation_links('menu-your-custom-menu-name');
 print theme('links__menu_your_custom_menu_name', array('links' => $menu));
?>

You can also add to template.php

function THEME_preprocess_page(&$vars) {

$menu = menu_navigation_links('menu-your-custom-menu-name');

$vars['custom_menu'] = theme('links__menu_your_custom_menu_name', array('links' => $menu));

}

the variable $custom_menu is available in the page tpl

| improve this answer | |
  • I understand that this goes into template.php, but how do I reference the menu in the page template? – tommyf Mar 15 '13 at 11:32
  • you can use this code directly in tpl. – Sibiraj PR Mar 15 '13 at 11:33
0

you can override your menu with hook_theme_tree() in template.php:

function THEME_menu_tree__MENUNAME($variables) {
  $menuTree = menu_build_tree('MENUNAME');

  foreach ($menuTree as $item) {

  }
}

and then create MENU BLOCK Or just print your menu directly in your page.tpl

| improve this answer | |
0

Well, Nothing from above worked for me with Drupal 7 but below code,

    $search_menu_name = "menu-search-box-menu";

   print theme('links', array('links' => menu_navigation_links($search_menu_name), 'attributes' => array('id' => $search_menu_name, 'class'=> array('links', 'inline'))));

The above code is like this, "menu-search-box-menu" is my custom menu name/ID. You can find it in that particular menu edit link.

Enjoy. :)

| improve this answer | |
0

I am using bellow code,It's working for me.

$main_menu = menu_navigation_links('menu-main-page'); print($main_menu);

| improve this answer | |
0

This has been driving me mad.

The easiest way by far is this...

In page.tpl.php where your custom menu name is "Custom Menu"

<?php

print drupal_render(menu_tree('menu-custom-menu'));

?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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