I've set my primary links as secondary links as well, so that different sets of secondary links display conditional on which primary link is selected. How can I get more control over this? Specifically, how would I make a certain set of secondary links appear when a certain node was displayed?

Comments

methy’s picture

I'm also wondering about this. It seems a lot of people are. Anyone got at least a hint? I can normally figure stuff out when pointed in the right direction..

jim0203’s picture

We might be able to work this out ourselves. I think that some function overriding is going to be called for. It's a good job I'm trying to learn PHP!

http://api.drupal.org/api/function/menu_secondary_links/6 is the function that generates the secondary links. It seems to just call http://api.drupal.org/api/function/menu_navigation_links/6, so that's where we'll be hacking about I think. As far as I can tell, it returns an array which contains all of the links which are going to be displayed in a menu.

I don't have time to look at this too closely right now, but I'm pretty certain that this is where we'll have to look. I'll post back when I've had some more time to work on this. If someone with more experience can step in to speed us up, that would be great.

One way to approach this might be via taxonomy: if a given page is of a certain category, then simulate to the functions above that it is infact another page, which has the required secondary links.

methy’s picture

Trust me, I've been looking. Either way, it seems we're getting closer. I've had a nice breakthrough, which is good.

$linksarray =  menu_navigation_links(variable_get('menu_secondary_links_source', 'secondary-links'), 1);
print_r($linksarray);

This will output an array which follows a trail and contain all the info of the secondary links which are under the primary link which the active page is under. If that makes sense.

I'll keep looking through the code and try to find a way to specify the which primary link you want to display the child links of, because eventually, I'll need to do that.

jim0203’s picture

Surely Drupal should be able to do this natively? I have a feeling we're missing something, like a module which will do all this for us. Dare I say it: Joomla! is very good at this sort of thing :-).

I thought for a moment that if we used path.module (and pathauto.module) we could rename nodes so that they would be contained "within" the menu item we wanted to be active in primary links. For example, on my site I've got example.com/multimedia, which contains example.com/multimedia/audio. I tried renaming a few audio nodes to things like example.com/multimedia/audio/title-of-audio-track, expecting Drupal to work out that I wanted the primary links for "multimedia" and "audio" to appear as active (this is what I was guessing would happen from my cursory glance at the code); but it didn't work.

So, is the module out there, or should we write it?

methy’s picture

$linksarray =  menu_navigation_links(variable_get('menu_secondary_links_source', 'secondary-links'), 1);
foreach($linksarray as $lvlarray){
  $attributesarray= $lvlarray['attributes'];
  if(isset($attributesarray['class'])){
    $lnkclass = $attributesarray['class'];
  }else{
    $lnkclass = "";
  }
  $lnkatitle = $attributesarray['title'];
  $lnkhref = $lvlarray['href'];
  $lnktitle = $lvlarray['title'];
  echo "<a href=\"".$lnkhref."\" alt=\"".$linkatitle."\">".$lnktitle."</a><br />";
}

This will output the links which are the children of the primary link which the current page is the child of. That's great for one of my functions, but I really need to be able to output the child links of any of my primary links. Any ideas? Anyone? It really shouldn't be this difficult. I'm almost resorting to a bunch of db_query() things, and I really can't imagine that's the best way to do it in a leading CMS.

methy’s picture

Or, simplified:

print theme('links', $secondary_links, array('id' => 'secondarymenu'));

methy’s picture

My problem is about to be solved... Try this...

$menu_render = menu_tree_page_data('primary-links');
				print_r($menu_render);

Read through that, and you'll eventually be able to do just about anything. The thing's fecking huge, and just as useful. I'm sure there's an easier way though. Seems strange to have to sift through a multidimensional array to get to anything around here.

Still, there it is. If you're not too good with arrays in PHP (and this is a biggun), then look online, as usual, there are plentiful great guides that can help you out.

EDIT: If you want to see how I got the important values out of it, let me know, and I'll post that.

jim0203’s picture

I've been a bit tardy on this - apologies - but does this solve the problem:

http://drupal.org/project/menu_block