Hi,
I am able to add classes to some menu items and not others.

Specifically, I am able to add classes to "navigation" menu items, but not to "primary link" menu items.

To help diagnose the problem I ran a test and it seems that "navigation" menu item links are getting passed to the function phptemplate_menu_item_link($link), but "primary" menu items links are not.

In case it is relevant, I am creating the primary-link menu during installation. Here is the code from my install profile that creates the primary-link menu:

$primary_links = array (
    array(
      'menu' => 'primary-links',
	  'title' => 'Home',
	  'path' => '<front>',
	  'weight' => 1,
	),
	array(
      'menu' => 'primary-links',
	  'title' => 'About Us',
	  'path' => 'about',
	  'weight' => 2,
	),
  );

  foreach ($primary_links as $item) {	
    install_menu_create_menu_item($item['path'], $item['title'], '', $item['menu'], 0, $item['weight']);
  }

Any thoughts about what may be happening?

Thanks very much,
Mindy

Comments

banjer’s picture

I have the same issue. I can't add classes to the "Primary Links" menu, or to a custom menu I have created. Hope this gets fixed.

couloir007’s picture

Same here. Unfortunately, without this, I can't use it.

masakura’s picture

Add the following code to theme template.php.

function phptemplate_links($links, $attributes = array('class' => 'links')) {
  if (function_exists('menuclass_to_link')) {
    foreach ($links as $key => $item) {
      if (preg_match('/^menu-(\d+)/', $key, $matches)) {
        $link = array(
          'mlid' => $matches[1],
        );
        $link['localized_options']['attributes'] = $item['attributes'];
        menuclass_to_link($link);
        $links[$key]['attributes'] = $link['localized_options']['attributes'];
      }
    }
  }
  return theme_links($links, $attributes);
}
buttonwillowsix’s picture

I am having the same issue. I added the above code to template.php and it did not help. No classes are added to Primary Links.

lloyyd’s picture

Status: Active » Needs work

Same here, the code for template.php didn't work. Is there anything new on this? I would like to use this module on my site..

lloyyd’s picture

Status: Needs work » Active

I got something. I don't know if anyone here read the readme.txt from the module.
It says that you have to copy some code to your template.php file to get menu_class to work.

I can add classes to my primary links after I copied the code.
So I just want to say RTFM to myself :-D

daniboy’s picture

Status: Active » Closed (won't fix)

This module is now obsolete. Please see the module's project page.