0
votes

I'm trying to style a custom menu within drupal.

I've sucessfully styled to display a background image, but the problem is that the menu item title still displays. So I get a nice image, with blazoned all over it.

Is there a template function I could use to format the custom menu and remove the text portion from the hyperlink?

I've done something similar on my primary links (see below) but I could do with some help figuring out how to do so on the custom menus.

function primary_links_add_icons() {
  $links = menu_primary_links();
  $level_tmp = explode('-', key($links));
  $level = $level_tmp[0];
  $output = "<ul class=\"links-$level\">\n";   
  if ($links) {
    foreach ($links as $link) {
        $link = l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']);
        $cssid = str_replace(' ', '_', strip_tags($link));
        $link = preg_replace('#(<a.*?>).*?(</a>)#', '$1$2', $link);
        $output .= '<li id="'.$cssid.'">' . $link .'</li>';
    };
    $output .= '</ul>';
  }
  return $output;
}

And then this called within the page.tpl.php

print primary_links_add_icons();

Thanks for any help!

1

1 Answers

1
votes

theme_menu_tree would be the way to resolve this on the template.php itself. The meat of your function would be identical to your function above. Documentation is at http://api.drupal.org/api/function/theme_menu_tree

But, I would recommend using CSS for what you're doing. If the text is removed entirely (via php) then you'll be depending on the user's browser to display the images and CSS properly and make navigation possible.

You might consider including both the image and the text, but making the text portion display: none so that it degrades more gracefully if CSS isn't loaded properly.