I'm trying to make a menu that has the parent items using images and child items as text... The way I'd like to see this output is

<ul class="menu">
  <li id="home" class="leaf"><a href="" title="Home"><span class="hidden">Home</span></a></li>
  <li id="about" class="expanded"><a href=" title="About" class="active"><span class="hidden">About</span></a>
    <ul class="menu">
      <li>.....etc....</li>
    </ul>
  </li>
  <li id="contact" class="leaf"><a href="" title="Contact"><span class="hidden">Coffee</span></a></li>
</ul>

I've found a php template to add to my template.php file that will add the id to the list-item for the background, this is

<?php
function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
  $link = menu_item_link($mid);
  $css_id = strtolower(str_replace(' ', '_', strip_tags($link)));
  return '<li id="' . $css_id . '" class="' . ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'. $link . $children ."</li>\n";
}
?>

I just need to figure out how to add the around the item title, everything else I can do with the css.

I have a (less than) basic understanding of php and how drupal works, but I know my way around CSS and have made a few custom themes so can figure that part out.

Any help is appreciated!
Thanks, KNerd Terry

Comments

uotonyh’s picture

Define a background-image for each root list item id in your CSS?

That might do the trick.

KNerd Terry’s picture

But I'm doing that already. I need to add the span around the item title, thats where I'm stuck... any ideas?

KNerd Terry’s picture

I just realized a bit of code was left out of this sentence:
"I just need to figure out how to add the *span with class=hidden* around the item title, everything else I can do with the css."

KNerd Terry’s picture

I found a function to change the menu_item_link but I'm getting an error!
warning: Missing argument 2 for phptemplate_menu_item_link()

Here are my two templates

<?php
function phptemplate_menu_item_link($item, $link_item) {
  $link_text = '<span>' . $item['title'] . '</span>';
  return l($link_text, $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL, NULL, FALSE, TRUE);
}


function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
  $link = phptemplate_menu_item_link($mid);
  $css_class = strtolower(str_replace(' ', '_', strip_tags($link)));
  return '<li id="' . $css_id . '" class="' . ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'. $link . $children ."</li>\n";
}
?>
KNerd Terry’s picture

but I'm not sure why. All I did was change the second function to this:

function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
  $link = menu_item_link($mid);
  $css_id = strtolower(str_replace(' ', '_', strip_tags($link)));
  return '<li id="menu_' . $css_id . '" class="' . ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'. $link . $children ."</li>\n";
}

So I just removed phptemplate_menu_item_link with menu_item_link and now it writes the span around the item title.

upupax’s picture

I'm trying to do the same thing in 6.x.
I found this, http://drupal.org/node/143322 , I thought to add a child menu item to use it as description of the parent and linking it to , but I always get warning: Missing argument 2 for phptemplate_menu_item_link().
Any suggestion?