I thought this was a great way to spice up the theme, this code actually works, but it returns a series of errors in addition to working. I wasn't going to post in the theme, but it looks so slick on the site, that maybe if it's some minor incompatibility with the theme, then if we can get it working it contributes nicely.

I've been playing around trying to get images to work as menu items in drupal 7 with earthish. Using a piece of code I was able to get here:

http://chrisshattuck.com/blog/how-use-images-menu-items-drupal-simple-pr...

I was able to get the images to display and function correctly in d7 with the code half way down the comments. I used the following code in my template.php file:

/**
* Implements theme_links()
*/
function earthish_links__system_main_menu($data) {
  // Allows for images as menu items. Just supply the path to the image as the title
  foreach($data['links'] as $name=>$link) {
    if (strpos($link['title'], '.png') !== false || strpos($link['title'], '.jpg') !== false || strpos($link['title'], '.gif') !== false) {

    $variables = array(
      'path' => $link['title'],
      'alt' => $link['attributes']['title'],
      'title' => $link['attributes']['title'],
      'attributes' => array('class' => 'main-menu-image', 'id' => $name . '-image'),
    );
    $link['title'] = $img = theme('image', $variables);
    $link['html'] = TRUE;  //otherwise theme_link will use check_plain on the title
    }
  $data['links'][$name]=$link;
  }
  return theme('links', $data);
}

The images are now displaying correctly in the menu, but it is returning the following errors seven times, one pair for each menu item:

Notice: Undefined index: title in earthish_links__system_main_menu() (line 89 of /home/.../sites/all/themes/earthish/template.php).
Notice: Undefined index: title in earthish_links__system_main_menu() (line 90 of /home/.../sites/all/themes/earthish/template.php)

Anyone know why? I would love to leave my graphic menu!

Comments

ishmael-sanchez’s picture

Assigned: Unassigned » ishmael-sanchez
Status: Active » Fixed

Exactly as the comment states, you don't have a title defined. If you debug the $data using either kpr (if you have the devel module) or print_r you will notice that 'title' => $link['attributes']['title'] doesn't have titles defined for your menu items. Remove that line, comment it out, or add descriptions to your existing menu items.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.