The Web Developer's Blog has been discontinued. I am now maintaining a new blog that is related to my company, Blue Piccadilly. The most popular articles from this blog (by monthly page views) have already been republished on the new blog, and indeed those original pages on this blog are being redirected to their new location. I'll probably keep these pages up here for a while. At least until the domain expires.

Output secondary links as a menu tree

21-Nov-2007
Filed under: Drupal, Drupal 5.x

Thanks for this posting goes to rapidsynergy for posting the solution in this comment on the Drupal forum.

Problem: You're using $secondary_links to display the children of the active menu item in $primary_links, but $secondary_links has children too and they aren't displaying when their parent becomes active.

Solution: Add the following snippet to your template.php file:

<?php
/**
* Output $secondary_links as a menu tree.
*/

function secondary_menu_tree() {

 
// get the menu items that lead to the current menu item
 
$active_trail =_menu_get_active_trail();
 
 
// get the menu id of the active top-level link
 
$mid = $active_trail[0];
 
 
// get the primary menus id
 
$pmid = variable_get('menu_primary_menu', 0);
 
 
//do they match?          
 
if ($active_trail[0] == $pmid) {
    return
theme('menu_tree', $active_trail[1]);  //create a tree starting from level 2
 
}

}
?>

Now, add the following line to your theme wherever you want to show the secondary menu items:

<?php print secondary_menu_tree(); ?>

Comments

So is this site already lapsed its domain expiration due then? Too bad when sites keep on redirecting you to new locations. Just when you're about to get the feel of the site then this redirection happens. By the way, you posting tips on output secondary links as a menu tree may have just been the one that I am looking for.

Gregory
Mark from carrelage imitation parquet 

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <i> <b> <cite> <code> <a>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.