On a new default install of D6, I very sure that I can:

- place 'blogs' in the primary menu as a parent item
- place 'my blog' in the primary menu as a child of 'blog'.

When I click on 'blogs' in the primary menu, the blog listing page will of course appear, but also
'my blog' will appear in the secondary menu. However, somewhere along the line
this desired behaviour always stops functioning! I don't know why.

I'm trying to build a menu system like this one:

http://www.nydailynews.com

If you click on 'gossip', the sub items appear underneath after the gossip page loads.
I've seen drupal do this! But I'm pulling my hair out trying to make it do it again.

FYI, I'm using the following in my page-tpl.php to place the menus, as opposed to using a block:

<div id="nav">
<?php if (isset($primary_links)) : ?>
<?php print theme('links', $primary_links) ?>
<?php endif; ?>
</div><!-- /primary nav -->

<div id="nav2">
<?php if (isset($secondary_links)) : ?>
<?php print theme('links', $secondary_links); ?>
<?php endif; ?>
</div> <!-- EDIT: added /secondary nav -->

Items simply added to the secondary menu do display. What I'm missing is the interaction between primary and secondary - the child displaying in the secondary menu when its primary parent item is selected.

Thanks for any assistance.

Comments

-Anti-’s picture

As usual, after looking into the problem for several hours, five minutes after posting
to the forum I found the answer:

In admin > menu > settings you simply set the source for the secondary links to 'primary' links.

It hasn't got quite the right behaviour, because unlike the menu on nydailynews.com, once the
secondary link is clicked, the parent loses its highlight, and so the user could get a bit lost,

But, hey! It'll do!

Cheers.

dnewkerk’s picture

It appears this will be fixed when Drupal 6.3 is released: http://drupal.org/node/249571
(new active-trail class to help style the menu path... if you need it immediately, consider trying out the patch)

On one of my Drupal 5 sites, I'm using some code I found in another theme to help solve the issue (giving me adequate hooks for my CSS). Here you can see it functioning.

In case it's helpful, here's the code from my template.php:

/**
 * Override theme_links to include <span> in list.
 */
function phptemplate_linksnew($links, $attributes = array('class' => 'links')) {
  $output = '';

  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = '';

      // Automatically add a class to each link and also to each LI
      if (isset($link['attributes']) && isset($link['attributes']['class'])) {
        $link['attributes']['class'] .= ' ' . $key;
        $class = $key;
      }
      else {
        $link['attributes']['class'] = $key;
        $class = $key;
      }

      // Add first and last classes to the list of links to help out themers.
      $extra_class = '';
      if ($i == 1) {
        $extra_class .= 'first ';
      }
      if ($i == $num_links) {
        $extra_class .= 'last ';
      }
	  
	 
	  // Add class active to active li 
	  $current = '';
	  if (strstr($class, 'active')) {
	    $current = ' active';
	  }	

	  $output .= '<li class="'. $extra_class . $class . $current .'"><span>';
	  
	  // Is the title HTML?
      $html = isset($link['html']) && $link['html'];

      // Initialize fragment and query variables.
      $link['query'] = isset($link['query']) ? $link['query'] : NULL;
      $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;

      if (isset($link['href'])) {
        $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
      }
      else if ($link['title']) {
        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</span></li>\n";
    }

    $output .= '</ul>';
  }

  return $output;
}

And here's code from my page.tpl.php:

  <?php if (isset($primary_links)) : ?>
    <?php print theme('linksnew', $primary_links, array('class' => 'links primary-links')) ?>
  <?php endif; ?>
  
  </div><!-- /header -->

  <div id="secondary-links">
    <?php if ($secondary_links) : ?>
      <?php print theme('links', $secondary_links, array('class' => 'links secondary-links')) ?>
    <?php endif; ?>
  </div>

-- David
absolutecross.com

-Anti-’s picture

Thank you for taking the time to post that information.
I applied the patch and it works beautifully.

Cheers!

icubyx’s picture

Hi,
Thanks for a great explanation. I just implemented it on a site I am building and works great. I wanted to know whether it is possible to have the Parent Link as the header of the secondary links?
Thanks for any help.
icubyx

-Anti-’s picture

> I wanted to know whether it is possible to have the Parent Link as the header of the secondary links?

Sorry, I don't understand what you mean.

Also, just to note, D6.3 *does* now contain the 'active-trail' css class, so this patch now isn't necessary
for that version and above.