Placing Secondary Links in a Block
When designing a custom theme I sometime want to put the set of secondary, or sub-page links, inside of a block in the sidebar. The secondary links are the children of the primary links, which you designate when creating the links. This makes creating sub-pages easy, even for non-programmers, because when creating a new page, they can indicate in the menu section that it is a "sub-page" of a primary link (even if the primary link isn't actually a page, in the case of the contact form) and the block of links will automatically be created on the page.
Instead of this "hack" I could have just recoded my themes page.tpl.php and re-designed the theme to place the sub-links in a sidebar, but this work around will give you a bit more flexibility in the location of your links (you can put them in any block section) and makes it easier to fit your links into existing themes.
Set your menu settings to have "Primary Menu" as the menu for both Primary and Secondary links, then create a new block and put this snippet of code into it. Make sure that you set the block to show up on all pages, and the input type to "php".
<?php $trail = _menu_get_active_trail();
if ($trail[0] == variable_get('menu_primary_menu', 0))
{
print theme('menu_tree',$trail[1]);
} ?>This menu will show up on the parent and child pages for the primary menu. It's clever.
NOTE:The block will not display on primary link pages that have no secondary links - so you don't have to worry about having a weird menu with nothing in it on every page.
You will need to remove or comment out the secondary links code from you page.tpl.php page in your theme to prevent it from showing up twice. It looks something like this:
<?php if ($secondary_links): ?>
<div id="secondary">
<?php print theme('links', $secondary_links); ?>
</div><!-- /#secondary -->
<?php endif; ?>
This is where I found this nifty chunk of code: http://drupal.org/node/78902
Comments
Post new comment