3

I have the following navigation, displayed in page.tpl.php:

theme('links', array('links' => menu_navigation_links('menu-site-navigation'))); 

There are four navigation elements that show up. I would like to display the description that goes along with these elements as well, how do I go about that?

In my template.php file I have the following code, but I can't figure out how to only apply this change to menu-site-navigation

function MYTHEME_link($variables) {
   // if there is a description for the menu item, show it
  if(!empty($variables['options']['attributes']['title'])){
      return '<a href="' . 
      check_plain(url($variables['path'], $variables['options'])) . 
      '"' . drupal_attributes($variables['options']['attributes']) . '>' .
      ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . 
      '</a><div class="description_nav">' . $variables['options']['attributes']['title'].'</div>';
  }
  else{ 
    return '<a href="' . 
    check_plain(url($variables['path'], $variables['options'])) . '"' .
    drupal_attributes($variables['options']['attributes']) . '>' .
    ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) .
    '</a>';
  }

}

2 Answers 2

0

Here are two things that may help you get this going:

  1. It looks like you're calling the theme_links() rather than the theme_link() function in your page.tpl.php file, so make sure that the call and theme function implementation match.
  2. You could add additional information to your links when you theme them to distinguish them from other links. For example, notice how I'm adding an id in the 'attributes' section below, so I can check for it later, in my theme_links implementation

Does that help?

 print theme('links', array(
  'links' => $secondary_menu,
  'attributes' => array(
    'id' => 'secondary-menu',
    'class' => array('links', 'inline', 'clearfix'),
  ),
  'heading' => array(
    'text' => $secondary_menu_heading,
    'level' => 'h2',
    'class' => array('element-invisible'),
  ),
));
0

An alternative solution to what you are doing that requires no coding is the menu descriptions module, which allows you to create menu descriptions blocks for your menus via the Drupal admin UI and then position those block where you like.

The blocks will display your menus along with descriptions that have been set for those menu items.

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.