views:

307

answers:

1

I have a preprocess function that works fine when the menu is single level list. However I would like it to work w/ suckerfish menus. I want to add a class to the top level menu item so that I can style it. This is the code I used for the single level menu:

function cti_flex_preprocess_page(&$vars, $hook) {

// Make a shortcut for the primary links variables
$primary_links = $vars['primary_links'];

// Loop thru the menu, adding a new class for CSS selectors
    $i = 1;

    foreach ($primary_links as $link => $attributes){
        // Append the new class to existing classes for each menu item
        $class = $attributes['attributes']['class'] . " item-$i";

        // Add revised classes back to the primary links temp variable
        $primary_links[$link]['attributes']['class'] = $class;
        $link['title'] = '<span class="hide">' . check_plain($link['title']) . '</span>';
        $i++;
        } // end the foreach loop

// reset the variable to contain the new markup
$vars['primary_links'] = $primary_links;

}

I've been trying to use the menu_tree() function to no avail, for example:

function cti_flex_preprocess_page(&$vars, $hook) {

// Make a shortcut for the primary links variables
$primary_links = $vars['primary_links'];

// Loop thru the menu, adding a new class for CSS selectors
    $i = 1;

    foreach ($primary_links as $link => $attributes){
        // Append the new class to existing classes for each menu item
        $class = $attributes['attributes']['class'] . " item-$i";

        // Add revised classes back to the primary links temp variable
        $primary_links[$link]['attributes']['class'] = $class;
        $link['title'] = '<span class="hide">' . check_plain($link['title']) . '</span>';
        $i++;
        } // end the foreach loop

// reset the variable to contain the new markup
$vars['primary_links_tree'] = menu_tree(variable_get('menu_primary_links_source', '$primary_links'));

}

Any ideas would be greatly appreciated.

A: 

Well, I gave up on this and found a great module that does what I need; Nice Menus.

http://drupal.org/project/nice_menus

Full css control of menus, excellent module.

slimcady