如何在节点模板中显示父菜单项?Drupal 7

0 drupal-7

如何在节点模板中显示父菜单项?

我想显示父菜单项和当前页面; 但我不需要别人.

编辑:我启用了菜单breadcrumb模块并添加了以下代码:

<?php              
                $menuParent = menu_get_active_trail();
                if (sizeof ($menuParent) >= 2 && $menuParent[2]) {
                     $menuParent = $menuParent[1]['link_title'];
                     print $menuParent; 
                } 
            ?>
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我没有第二级导航的页面出错:错误:注意:未定义的偏移量:2 in include()

我认为我的条件sizeof将处理问题,但不工作.

Dun*_*moo 8

使用PHP数组工具为您提供数组中正确的项目:

<?php
  $menuParent = menu_get_active_trail();
  //get rid of the last item in the array as it is the current page
  $menuParentPop = array_pop($menuParent);
  //Just grab the last item in the array now
  $menuParent = end($menuParent);
  //if it is not the home page and it is not an empty array
  if(!empty($menuParent) && $menuParent['link_path'] != ''){
    print $menuParent['title'];
  } else{
    print $title;
  }
?>
Run Code Online (Sandbox Code Playgroud)