Posted by Chris Graham on October 8, 2011 at 8:11pm
Hi all,
Just wondering if someone could help me out with a little brain teaser I've been having. I want to add span tags inside menu links in one specific menu to allow some mad theming :|
In D6 you can override this function in template.php:
<?php
function theme_menu_item_link($link) {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
return l($link['title'], $link['href'], $link['localized_options']);
}
?>and if I add html=>true to the localized options and add a span around the title it works... but it does this for every menu.
Is there a way to target a specific menu when overriding this in template.php?
Cheers,
Chris

Comments
Hi Chris, If its for theming
Hi Chris,
If its for theming you can use http://drupal.org/project/menuclass to add classes to menu items...
you could also try http://drupal.org/project/menu_attributes
Igzi
Hi Igzi, Unfortunately adding
Hi Igzi,
Unfortunately adding a class won't help.
Basically I want to make the link into a block of 240px * 120px and then have the span inside the link in order to position that top right inside the link so that I can style both the background on the link and the background on the span independently and yet still have the full area linked (not just the text).
There is no way to do what I want to do without adding an extra tag inside the link tag (not that I know of anyway).
I've actually worked out how to do it for a single menu, the $link array in the function I mentioned contains menu_name. I can just do a switch based on that and output the span for just the menu I need it for.
Cheers,
Chris
I came across a similar issue a few weeks ago
My own hack was to load the menu and replace the string - I couldnt find another way
<?php$book_link = $book_node->book;
//print_r($book_node->book);
//print_r($book_link);
//$tree = menu_tree_all_data($book_link['menu_name'], $book_link, $book_link['depth'] + 1);
$tree = book_children($book_link);
$tree = str_replace(' class="leaf"', ' class="bulletblue"', $tree);
$tree = str_replace(' class="first leaf"', ' class="first bulletblue"', $tree);
$tree = str_replace(' class="last leaf"', ' class="bulletblue"', $tree);
$tree = str_replace(' class="collapsed"', ' class="bulletblue"', $tree);
$tree = str_replace(' class="menu"', '', $tree);
return $tree;
?>