3

I'm trying to print the secondary links for the main menu as expanded in my template node--products.tpl.php. In my menu I have three levels.

-Products

--Product category

---Product

-Another menu link

The result should be a menu with all product categories with the child items. I don't want to print the root level in the menu; I only want the secondary level, and its children to appear.

I have tried to print the secondary menu like this, but the child items doesn't appear. Any help appreciated.

$secondary_menu = theme_get_setting('toggle_secondary_menu') ? menu_secondary_menu() : array();
print theme('links__system_main_menu', array(
    'links' => $secondary_menu,
    'attributes' => array(
    'id' => 'main-menu-links',
    'class' => array('links', 'clearfix'),
  ),
    'heading' => array(
    'text' => t('Main menu'),
    'level' => 'h2',
    'class' => array('element-invisible'),
  ),
));
  • I have tried the function menu_tree_output() in this answer. The problem is that I don't want to print the root level in the menu. Only the secondary level and the children to the secondary menu. I can't figure it out how I can do that. – user1149117 Oct 22 '12 at 13:41
1

In your themes template.php add the following:

function THEMENAME_preprocess_page(&$variables) {

  // Get the entire menu tree (you can replace this string with any menu you want)
  $main_menu_tree = menu_tree_all_data('main-menu');

  // Generate structure for rendering the menu.
  $menu = menu_tree_output($tree);

  // Replace the $menu array with the #below array beloning to the first top 
  // level menu item.
  $menu = $menu[key($menu)]['#below'];

  // Add $main_menu_no_top as a variable to use in our theme
  $variables['main_menu_no_top'] = $menu;
}

Then, in page.tpl.php, you can just use:

<?php print render($main_menu_no_top); ?> 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.