By Mark Nielsen on
Hi -
I'm trying to write a theme function which causes the current menu item to be shown not as a link but as emphasised text.
The problem is that this function causes drupal to not display any menu items after the current item.
Here's my function:
function phptemplate_menu_item_link($item, $link_item) {
/***
* Overrides the HTML output for all links in block menus
* - no link tag is provided on the menu item for the current page
* - <strong> tags are added to the current page's menu item, to emphasise it as the current page.
*/
$this_page = menu_get_active_title();
$unlinked_item = "<strong>". $item['title'] ."</strong></li>\n"; // causes menu to stop at this p
oint.
$linked_item = l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
if ($item['title'] == $this_page || drupal_is_front_page() && $item['title'] == "Home" || $active) {
return $unlinked_item;
}
else {
return $linked_item;
}
}
Something in my $unlinked_item statement seems to be causing this problem - perhaps the 'l' function needs to be triggered in some way to keep the loop going to complete the menu list?
Any help (or even attempts at help) would be much appreciated - I confess I am stumped here :/
Comments
A different approach, and now it works :)
Hi - I took a slightly different approach here, which has given me the result I wanted.
Instead of trying to alter the way Drupal builds the link, I've added a regular expression to replace the link tags with strong tags. Here's what I mean:
I'm not sure I'm entirely happy with this. I'd rather intervene before Drupal builds the link, than allow it to process the link and then re-process it with a regular expression. But perhaps the performance difference isn't anything to worry about?
Finally, as an observation, it seems the bit of Drupal that generates the HTML for links is hard-coded into the core. Wouldn't it be better if the l function was themeable? Or perhaps this is already on the cards for version 6?
Mark
flet.org
thank you very much - this works.
Yes cool, it DOES work perfectly, although to my limited understanding it seems the IF clause is missing some braces around (drupal_is_front_page() && $item['title'] == "Home") .. at least in C it would. Anyways, cool easy fix, cheers!
Nice
thanks
Hi! I need to unlink one menu
Hi!
I need to unlink one menu item (because it's a header of drop-down menu). How can i use your code, and where this function is called?