How to print a custom menu in Drupal 7?

2019-03-12 13:42发布

I have created a menu in Drupal 7 and created links to pages under that menu.

I named my new menu "Site Menu"

In my page.tpl.php where I want my menu to appear I have put this in place:

<?php print theme('links', menu_navigation_links('menu-site-menu')); ?>

After I have cleared my cache and refreshed my page my menu doesn't appear.

I am stumped. Any help would be greatly appreciated.

标签: drupal menu
3条回答
小情绪 Triste *
2楼-- · 2019-03-12 13:58

Berdir answer is correct. Drupal 7 theme_links function also more vastly uses arrays. For example if you would like to add another class name to the so that it is you would code it like this:

<?php print theme('links', array('links' => menu_navigation_links('menu-site-menu'), 'attributes' => array('class'=> array('links', 'site-menu')) ));?>
查看更多
萌系小妹纸
3楼-- · 2019-03-12 14:03

theme() now recieves an array of arguments. For example:

<?php
print theme('links', array('links' => menu_navigation_links('menu-site-menu')));
?>
查看更多
成全新的幸福
4楼-- · 2019-03-12 14:06

Well, it is bit confusing from above solutions to print menu. But below code worked for me, hope this will work for y'all,

    $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. :)

查看更多
登录 后发表回答