PhpTips.im - Everything about php - Download CMS, find tips and tricks, code snippetz, classes and more and more...
Bookmark this page !
   

Articles

    Home » Articles » PHP Snippets » Add 'active_trail' class to a 'menu_tree_all_data' result
Published on : 15.05.2010 Category : PHP Snippets Viewed : 87 times.

Code:


  1. ...
  2. $data = menu_find_active_trail(menu_tree_all_data(...));
  3. ...
  4.  
  5. /**
  6.  * Wrapper function
  7.  */
  8. function menu_find_active_trail(&$menu_tree) {
  9. $item = menu_get_item();
  10. _menu_find_active_trail($menu_tree, $item);
  11. return $menu_tree;
  12. }
  13.  
  14. /**
  15.  * Recursive function to find the active menu and the active trail in the given tree.
  16.  */
  17. function _menu_find_active_trail(&$menu_tree, $item) {
  18. $level_is_expanded = FALSE;
  19. foreach($menu_tree as &$menu_item) {
  20. $link = &$menu_item['link'];
  21. if ($link['href']==$item['href']) { // Found the exact location in the tree
  22. $link['active'] = TRUE;
  23. $link['in_active_trail'] = TRUE;
  24. return true;
  25. } else {
  26. if ($link['has_children']) {
  27. $result = _menu_find_active_trail($menu_item['below'], $item);
  28. $link['in_active_trail'] = $result;
  29. if ($result) $level_is_expanded = TRUE;
  30. }
  31. }
  32. }
  33. return $level_is_expanded;
  34. }



Add this article in :

 

There is not yet any comment !



1091 Rating: 0.0/10 (0 votes cast)

 

 Members
Log In !
Email Address :

Password :


Change my passowrd !
Sign Up !
We have : 3 members.
Latest member : albans
 
 Last Posts
 
 Advertising
 
©PhpTips.im 2010
Powered by PikaCMS.
Quick Links :
Home | Browse all articles | Downloads | Terms of Use
RSS RSS 2.0 : Articles | Downloads ATOM : Articles | Downloads