Display children of the actual menu node (Not all the menu tree)

Last modified: November 16, 2006 - 00:51

In our web (http://www.fundacionalzheimur.org/formacion) we use the structure of the menu primary links, but we haven't found an automatic way of present, as in a book, the child nodes when displaying a menú node.

Our solution is including this php snippet in the node.tpl template, just before the content, in a div floating right:

.... <div class="itemtext">
<!-- Expanded Menu for navigation -->
<?php
$mid
= menu_get_active_nontask_item();
 
$active = menu_get_item($mid);
 
// this is a top-level link in your primary links
 
if($active['pid'] == variable_get('menu_primary_menu', 0)){
   
$output.= theme('menu_tree',$mid);
        print(
'<div id="menubox"><h2>navigate</h2>');
    print
$output;
    print(
'</div>');
  }

?>

<!-- end of menu  -->
    <?php print $content?>
  </div> .....

The CSS would be:
#menubox {
  display: block;
  float:right;
  width: 35%;
  margin-left: 18px;
  margin-bottom: 18px;
  padding-bottom: 5px;
  background: #fff url(images/Fondo_Logo_menu.jpg) no-repeat bottom right;
}
#menubox h2 {
background: #fff  url(images/block-quote_left.gif) no-repeat top left;
color: #6A0D22;
padding: 7px 7px 7px 37px;
margin-bottom: 2px;
line-height: 0.6em;
}

See module submenutree

bengtan - November 12, 2007 - 04:46

While surfing, I came across this (apparently) old page. If you have a Drupal 5.x site, you may be interested in submenutree.

Submenutree drupal 6

donpositivo - February 19, 2009 - 13:04

Also available for Drupal 6

In Drupal 6

gallandv - January 26, 2009 - 03:29

I don't know if it's exceedingly complicate, but this is what worked for me to display inside a page just the children (and their childrens and so on) of the current menu item.

<?php
    $item
= menu_get_item();
   
$tree = menu_tree_page_data('primary-links');
    list(
$key, $curr) = each($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;
?>

In Drupal 6

saiprasad_saiprasad - April 17, 2009 - 12:13

where your code be added

modifcation w/ third-level support

jhchnc - May 5, 2009 - 18:12

<?php
foreach( $tree as $k => $v ) {
   
$thirdLevel = array();  // this will hold third levels as we iterate the tree
   
list($key, $curr) = each($v);  // capture current node in tree
   
while ($curr) {
      if (
is_array($curr['below']) ) {  // if this node has children
       
array_push( $thirdLevel, $curr['below']);  // push them into thirdLevel
       
unset( $tree[$key]['below'] );  // unset the child nodes in main tree, so no reuse
       
if ( count($thirdLevel) > 0 ) {  //  if there are any children
           
foreach( $thirdLevel as $key => $val ) { // we pushed multiples, right
               
$links = theme_menu_tree(menu_tree_output($val)); // these get syled within a ul class=menu... good enough hook for me!
               
$output .= $links;
            }
        }
       
$curr = FALSE;
      }
      else {
// well, no children here, so these are second level links
       
list($key, $curr) = each($tree);  // capture node
       
foreach( $curr as $k => $v ) {
            if (
is_array($v) && $v['href'] ) {  // they aren't all links!
               
$output .= '<a href="/'.$v['href'].'">'.$v['title'].'</a>';
            }
        }

      }
    }
}
?>

oh

jhchnc - May 5, 2009 - 18:13

and it be added in a custom function you call

What custom method?

md_drupal - May 11, 2009 - 15:42

You mentioned custom method. Would you be able to provide the entire flow (template.php, page.tpl.php)?

Thank you!

Menu block module

foxtrotcharlie - June 21, 2009 - 16:37

This very flexible module may also do the trick: http://drupal.org/project/menu_block

*****************************
South Africa Drupal Development
*****************************

 
 

Drupal is a registered trademark of Dries Buytaert.