Show subset or subcategory of a Drupal menu

Show subset or subcategory of a Drupal menu

Footer menus aren’t as popular as they used to be, but still used often for SEO. You may not want to include the entire menu on the footer, maybe just a section or a subcategory. Here is one way of doing that.

function mymodule_mainmenu_subnav($link_name) {
  $links = array();
  $menu_tree = menu_tree_all_data('main-menu'); // grab main-menu items
  foreach ($menu_tree as $item_name => $item) { // loop through all menu items
    if (strpos($item_name, $link_name) !== FALSE) { // if $link_name is found in $item_name
      foreach ($item['below'] as $sub_item) { // loop through all 'below' items
        $links[] = l($sub_item['link']['link_title'], $sub_item['link']['link_path']);
      }
      return theme('item_list', array('items' => $links)); // return list of links
    }
  }
}

Good Luck!

No Comments Yet.

Leave a comment