I am trying to set up a custom menu in my theme, but when the output is displayed the children do not show up. The primary links show up, but if I set any of the links to have children, they do not show. I've tried using the menu_tree function but I couldn't figure out how to custom theme that either. Any help would be much appreciated. The code I am using is:

<div id="menu-container">
	<?php if (is_array($primary_links)) : ?>
		<ul id="menu">
			<?php foreach ($primary_links as $link): ?>
				<li><?php $href = $link['href'] == "<front>" ? base_path() : base_path() . drupal_get_path_alias($link['href']);
			        print "<a href='" . $href . "'>" . $link['title'] . "</a>"; ?>
				</li>
			<?php endforeach; ?>
		</ul>
	<?php endif; ?>
</div>

The output I'm looking for should look like:

<div id="menu-container">
	<ul id="menu">
		<li><a href="/home">HOME</a></li>
		<li><a href="/events">EVENTS</a>
			<ul>
				<li><a href="/events">Upcoming Events</a></li>
				<li><a href="/previous-events">Previous Events</a></li>
			</ul>
		</li>
		<li><a href="/image">PICTURES</a></li>
		<li><a href="/contact">CONTACT</a></li>
	</ul>
</div>

Comments

suryanto’s picture

You can use menu_tree function:

<div id="menu-container">
  <?php
  print menu_tree('primary-links');
  ?>
</div>

For alternative solution, you can use menu block module:

http://drupal.org/project/menu_block

--
Suryanto Rachmat

mtropea55’s picture

Thanks suryanto, but the problem I had was I couldn't stylize the <ul> and <li> tags. Drupal kept adding it's own classes. I think there is a function override I could put into the templates.php but I couldn't find anything.

chronnus’s picture

Here's the code I use to make sure the children menu items show up:

        <ul class='links sf-menu' id="navlist">
        <?php
            $tree = menu_tree_page_data('primary-links');

              $output = '';
              $items = array();

              // Pull out just the menu items we are going to render so that we
              // get an accurate count for the first/last classes.
              foreach ($tree as $data) {
                if (!$data['link']['hidden']) {
                  $items[] = $data;
                }
              }

              $num_items = count($items);
              foreach ($items as $i => $data) {
                $extra_class = NULL;
                if ($i == 0) {
                  $extra_class = 'first';
                }
                if ($i == $num_items - 1) {
                  $extra_class = 'last';
                }
                $link = theme('menu_item_link', $data['link']);
                if ($data['below']) {
                  $output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
                }
                else {
                  $output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
                }
              }

        print $output;
        ?>
        </ul>

You can use theme_menu_tree, theme_menu_item, and theme_menu_item_link to override the respective outputs. Hope that helps!

mtropea55’s picture

Thanks chronnus. Your function worked great.