[Решено] программно вывести все пункты выбранного пункта меню

Главные вкладки

Аватар пользователя oksale oksale 13 марта 2009 в 20:42

Что нужно: вывести все пункты и подпункты из выбранного пункта меню.
Нашла такой пример кода:

<?php
$item 
menu_get_item();
    
$tree menu_tree_page_data(menu_get_active_menu_name());
    list(
$key$curr) = each($tree); //print_r($tree);

    

while ($curr) {
      
// Terminate the loop when we find the current path in the active trail.
      
if ($curr['link']['href'] == $item['href']) {
        
$tree $curr['below'];
        
$curr FALSE;
      }
      else {
        
// Add the link if it's in the active trail, then move to the link below.
        
if ($curr['link']['in_active_trail']) {
          
$tree $curr['below'] ? $curr['below'] : array();
        }
        list(
$key$curr) = each($tree);
      }
    }
    
$menuhtml theme_menu_tree(menu_tree_output($tree));
    print 
$menuhtml;
?>

Но он выводит только следующий уровень меню. А мне нужна вся ветка - от первого уровня и до последнего.

Комментарии

Аватар пользователя Loac Loac 13 марта 2009 в 21:13

Однажды в модуле я делал так (для пятерки):

<?php
function loac_menu_tree($pid 1) {
  
$menu menu_get_menu();
  
$output '';

  if (isset(

$menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
    foreach (
$menu['visible'][$pid]['children'] as $mid) {
      
$type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;

      

$children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;

      

$output .= theme('menu_item'$midtheme('loac_menu_tree'$mid));
    }
  }
  
  return 
$output;
}

function 

theme_loac_menu_tree($pid 1) {
  if (
$tree loac_menu_tree($pid))
    return 
"\n<ul class=\"menu\">\n"$tree ."\n</ul>\n";
}
?>

И, я думаю, можно подсмотреть в модуле site_map.

Аватар пользователя oksale oksale 16 марта 2009 в 19:02

Сама написала функцию. Функция выводит ветку активного меню - от первого уровня до текущего+1.

<?php
function page_nav()
{
    
$tree menu_tree_page_data(menu_get_active_menu_name());
    
$tree prune_tree($tree);
    return 
theme_menu_tree_output($tree);
}

function 

prune_tree($tree)
{
    
$items = array();
    
    foreach (
$tree as $data)
    {       
        if (
$data['link']['in_active_trail'])
        {             
            
$items[] = $data;
        }
    }
    return 
$items;
}
?>
Аватар пользователя seaji seaji 22 марта 2009 в 12:01

Я использую такой код:


<?php
$menu 
menu_tree_all_data('menu----------------0'64);
print 
menu_tree_output($menu['50000 Общая информация 64'][below]);
?>

Только нужно знать координаты начальной точки: $menu['50000 Общая информация 64']
И в каком меню находится ваш стартовый подпункт меню: 'menu----------------0', 64
Чтоб это узнать можно сделать

<?php
print_r
(menu_tree_all_data())
?>