Closed (duplicate)
Project:
Nice Menus
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
30 Aug 2007 at 02:25 UTC
Updated:
10 Feb 2008 at 04:54 UTC
Hi. I have noticed that many people are asking to have one feature - namely - to have parent <li> tag to have .active class attribute when child is selected/clicked.
I have found this code but couldn't manage to make it working with drupal 5.2.
Probaly somebody will make it and share with us.
WOULD BE HIGHLY APPRECIATED IF THIS FEATURE IS IPLEMENTED INTO NEAREST NICE.MENU RELEASE.
<?php
function _nice_menu_tree($pid = 1) {
$menu = menu_get_menu($pid);
$output['content'] = '';
$output['subject'] = $menu['items'][$pid]['title'];
$trail = _menu_get_active_trail();
if ($menu['visible'][$pid]['children']) {
foreach ($menu['visible'][$pid]['children'] as $mid) {
$is_active = array_search($mid, $trail);
if (count($menu['visible'][$mid]['children']) > 0) {
$class_tags = $is_active ? " class=\"active menuparent\"" : "class\"menuparent\"";
$output['content'].= "<li id=\"menu-$mid\"$class_tags>".menu_item_link($mid);
$output['content'].= "<ul>";
$tmp = _nice_menu_tree($mid);
$output['content'].= $tmp['content'];
$output['content'].= "</ul>";
$output['content'].= "</li>";
}
else {
$class_tags = $is_active ? " class=\"active\"" : "";
$output['content'].= "<li id=\"menu-$mid\"$class_tags>".menu_item_link($mid)."</li>";
}
}
}
return $output;
}
?>
Comments
Comment #1
ivrh commentedI have changed nicemenus.module a bit to do what I want - I hope it'll be usefull to somebody else.
To use my code, find "function theme_nice_menu_tree" string (drupal 5.x ONLY) and replace the whole function with my code
Two thing you need to do:
1. Find out Menu ID and change $pid = ...;
2. Find out Top-level menu items ids ('pid' column in 'menu' table - one ID per one top-level menu item) and either change my values (if they go each after another - using placeholder in SQL statement below) or list them one by one using placeholder in SQL statement below.
This is the code:
Comment #2
add1sun commentedMoving to feature request. Note that the best way to get features into the module is to supply patches for your code so it is easier for others to test and play with.
Comment #3
add1sun commentedAlso retitling.
Comment #4
add1sun commentedArg, this is actually a duplicate of yet another issue: http://drupal.org/node/73902. I'll keep this as the main one since other dup'd issues point here already. PLEASE keep all discussion of this issue in one thread - this one.
Comment #5
add1sun commentedI'm adding this forum link here as well: http://drupal.org/node/188596
Comment #6
add1sun commentedMoving all feature requests to HEAD. We'll work on new features after the port to 6 is complete.
Comment #7
add1sun commentedPatches started in another thread so while this is older, I'm going to mark this duplicate. http://drupal.org/node/219804