Community Documentation

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

Last updated August 26, 2009. Created by tsaorin on October 5, 2006.
Edited by bekasu, puregin. Log in to edit this page.

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;
}

Comments

See module submenutree

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

Also available for Drupal 6

In Drupal 6

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

where your code be added

------------------------
Sai prasad

modifcation w/ third-level support

<?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

and it be added in a custom function you call

What custom method?

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

Thank you!

Menu block module

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

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

Page status

About this page

Drupal version
Drupal 4.7.x
Audience
Themers

Theming Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here