You are here

function theme_nice_menu_tree in Nice Menus 5

Same name and namespace in other branches
  1. 6 nice_menus.module \theme_nice_menu_tree()

Builds the inner portion of a nice menu.

Parameters

$pid: The parent menu ID from which to build the items.

$menu: Optional. A custom menu array to use for theming -- it should have the same structure as that returned by menu_get_menu().

Return value

An HTML string of properly nested nice menu lists.

1 theme call to theme_nice_menu_tree()
theme_nice_menu in ./nice_menus.module
General theming function to allow any menu tree to be themed as a nice menu.

File

./nice_menus.module, line 205

Code

function theme_nice_menu_tree($pid = 1, $menu = NULL) {
  $menu = isset($menu) ? $menu : menu_get_menu();
  $output['content'] = '';
  $output['subject'] = check_plain($menu['items'][$pid]['title']);
  if ($menu['visible'][$pid]['children']) {

    // Build class name based on menu path
    // e.g. to give each menu item individual style.
    foreach ($menu['visible'][$pid]['children'] as $mid) {

      // Strip funny symbols
      $clean_path = str_replace(array(
        'http://',
        'www',
        '<',
        '>',
        '&',
        '=',
        '?',
        ':',
      ), '', $menu['items'][$mid]['path']);

      // Convert slashes to dashes
      $clean_path = str_replace('/', '-', $clean_path);
      $path_class = 'menu-path-' . $clean_path;
      if (count($menu['visible'][$mid]['children']) > 0) {
        $output['content'] .= '<li id="menu-' . $mid . '" class="menuparent ' . $path_class . '">' . menu_item_link($mid);
        $output['content'] .= '<ul>';
        $tmp = theme('nice_menu_tree', $mid);
        $output['content'] .= $tmp['content'];
        $output['content'] .= "</ul>\n";
        $output['content'] .= "</li>\n";
      }
      else {
        $output['content'] .= '<li id="menu-' . $mid . '" class="' . $path_class . '">' . menu_item_link($mid) . '</li>' . "\n";
      }
    }
  }
  return $output;
}