Drupal: Icon on every link of a menu.

Override theme_menu_item() (includes/menu.inc)

edit/create template.php in your themes dir.

<?php
function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
  return
_phptemplate_callback('menu_item', array(
       
'leaf' => $leaf,
       
'mid' => $mid,
       
'children' => $children
   
));
}
?>

create a menu_item.tpl.php file

<?php
$link
= menu_item_link($mid);
$css_id = str_replace(' ', '_', strip_tags($link));
$output = '<li id="'. $css_id .'" class="'.
          (
$leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'.
         
$link . $children ."</li>\n";
print
$output;
?>

CSS:

li#link-one a{
background-image:url(images/link-one-li.png);
}

li#link-two a{
background-image:url(images/link-two-li.png);

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options