Add a submenu tree in a block
Warning: does not work for menu 'node/add' trail but works for 'admin'. The test done was with a custom menu. So feedback is very welcome!
You can add an expanded submenu of the primary links by creating a block containing the following code.
The end result will be a block containing a submenu of the active menu. By using block visibility the block is only visible for the appropriate submenus.
- Go to the admin/build/block/add page.
- Paste the following code into the block body:
<?php
$menu_trail= _menu_get_active_trail();
$menu_top_level = array_shift( $menu_trail);
// comment next line when finished testing using: // in front
print( 'top-level-id= ' . $menu_top_level .'<br/>');
$menu_sub_menu = array_shift( $menu_trail);
print( menu_tree( $menu_sub_menu));
?> - Be sure to check the PHP code.
-
Paste the following code into 'Page specific visibility settings':
<?php
// Fill in the appropriate top level ID's in a comma-separated list
$valid_top_levels = array(1, 2);
// Uncomment next line when finished testing
//return in_array( array_shift( _menu_get_active_trail()), $valid_top_levels);
return TRUE;
?> - Enable the checkbox 'Show if the following PHP code returns TRUE (PHP-mode, experts only).'
- Make the new block visible.
- When satisfied, uncomment the line as indicated in the above PHP code

theming
Thank you for this code. It is really helpfull.
When testing it, I realize that it would be better (for me) to use theme_menu_tree instead of menu_tree function as the first adds a "class=menu" to the root "ul" tag of the printed menu. This let you theme your block easier.
Again thx Drupal ;-)
Rafik