7

I would like to add pipes ("|") between menu items for one of the menus on my Drupal 7 site (theme name is "thompson"). I figured the best way to do this is to create a function in my template.php file called thompson_menu_link. I did that and it is successfully modifying the menus, but it's changing all the menus. Is there a way I can do this for just one menu on my site?

Currently, I used the admin pages to add my footer menu (url path: menu-footer-menu) to the Footer block. Should I call it a different way?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Brett F
  • 414
  • 6
  • 11
  • The part you added about the solution you adopted should be written as answer. If you wrote that as answer, I would up-vote it. `:-)` – apaderno Aug 29 '11 at 11:46
  • Sorry, new here. Didn't know if it was bad form to answer my own question and accept it. – Brett F Aug 29 '11 at 14:19

3 Answers3

6

Apparently Drupal core provides the ability to theme menu links by menu name. For the Main menu the following theme function should work

THEMENAME_menu_link__main_menu()

Alternatively you could use the Menu Block module to create menu blocks. Among other things the module creates additional theme suggestions. From the module's README:

Menu block uses Drupal core's menu theme functions. However, it also provides theme hook suggestions that can be used to override any of the theme functions called by it. ...

  • theme_menu_link() can be overridden by creating one of:
    • [theme]_menu_link__[menu name]()
    • [theme]_menu_link__menu_block()
    • [theme]_menu_link__menu_block__[menu name]()
    • [theme]_menu_link__menu_block__[block id number]()
daniels
  • 4,961
  • 2
  • 22
  • 11
2

I've messed with the thompson_menu_link() function a bit. I don't like how I did it, but it got the job done. Basically, it reads in the menu name, and uses a conditional to return the <li> element with a pipe afterward. Here's the whole block:

function thompson_menu_link(array $variables) {
  $element  = $variables['element'];
  $menuName = $variables['element']["#original_link"]["menu_name"];
  $sub_menu = '';

  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);

  if ($menuName == "menu-footer-menu" && !in_array("last",$element['#attributes']['class']) {
    $finalString = '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>|\n";
  }
  else {
    $finalString = '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
  }

  return $finalString;
}
apaderno
  • 28,547
  • 16
  • 75
  • 90
Brett F
  • 414
  • 6
  • 11
  • 1
    You have an error in if ($menuName == "menu-footer-menu" && !in_array("last",$element['#attributes']['class']) {. Needs another ) at the end. – canadiancreed Mar 13 '15 at 18:09
0

the best way you can make it is installing the following module:

http://drupal.org/project/menu_attributes

This module lets you add special classes to some menu entries, so you just have to add a class rightpipe and define that class like:

.rightpipe { border-right: 1px solid black }

or

.rightpipe { background: url(1pixel_line_separator.png) no-repeat center right }
3oheme
  • 143
  • 5