I am trying to use the new primary and secondary links system in 4.7, but don't quite get it, just like the users who have commented on the book page:
http://drupal.org/node/57823

Can anyone explain this?

Comments

charleyramm’s picture

I have found these confusing too. I don't think I can help you, but I would love to hear more about them.

I added an item called 'Logout' and it dissapears when I am not logged in. So I added an item called Login, but it doesn't do what you'd think.

good luck figuring it out.

Dave Alitz’s picture

I've got it working, but it's less than I hoped for. I guess I read the description and interpreted the feature as what I was wishing for rather than what it provides. When I went back and read it carefully, it turns out to be functioning just as advertised.

In administer>menus, construct a menu with your primary links at the root and secondary links as children of the primary links. Go to administer>settings>menus and point both the primary links and secondary links at the same menu.

Primary links are those whose parent is the root of the menu. Secondary links are the children of the Primary links. No other nodes in the menu hierarchy will appear as primary or secondary links.

  • If you select a primary link, the secondary links displayed will be the primary links children.
  • If you select a secondary link, the secondary links displayed will be its own siblings -- in other words, the secondary links displayed won't change.
  • If you descend into one of the branches (children, grandchildren, etc.) of a secondary link, the context sensitive menu will still display the siblings of the secondary link -- again, no change

I was hoping that the context sensitive menu would display the children of the current node as "secondary" links, but that's not the case. The only time the secondary links change is when you select a different primary link (or its offspring) or navigate to a node not in the menu hierarchy.

I guess what I'm really looking for is context sensitive child links as opposed to secondary links. I feel my users are overwhelmed by the number of items in menu. I'd like to limit it to primary links at the top, child links at the left, and breadcrumbs for the current branch.

venkat-rk’s picture

This is the clearest description of the primary links' working that I have read so far. Thanks a lot for writing this up. I will try it out and see if it works.

Dave Alitz’s picture

I apoligize. My description is inaccurate. Secondary links in fact show the current node and its siblings if it's in the menu.

mixey’s picture

How did u make it work?

I've got:
Site Menu:
---About
----Sub_about
-------subsub_about
----2_Sub_about
---Services
----Sub_services

I setuped like the handbook saying.

When I press About. in secondary section area renders Sub_about and 2_Sub_about.
But when I press Sub_about I don't see that it has childrens. (subsub_about)

Any ideas?
Thanks in advance!

venkat-rk’s picture

But when I press Sub_about I don't see that it has childrens. (subsub_about)

Do you mean you can't see the menu in an expanded form? Or, do you mean you can't see the children at all?

If it is the first, you have to go to admin>>menu, click on the edit link for Sub_about and check the box that says it should be expanded if it has children. If you don't want it to be permanently expanded, but only expand when someone clicks on Sub_About, don't check this box.

If you can't see the child menu items using either approach, clear (empty) the cache table in your site's drupal database using something like phpmyadmin (DON'T clear the menu table as it will delete all your custom menu items). This usually solves the menu issue.

mixey’s picture

:( It doesn't helped.

May be someone knows the way I can figure out in which section I'm right now?

I mean i need function, that will return ID of About menu if I'm in About, About->Sub, About->Subsub.
And return ID of Services if I'm in Services, Services->Sub, Services->Sub->Subsub.

$menu_id= this_magick_function();
$html_menu = theme_menu_tree($menu_id);
print $html_menu;
asparagus’s picture

hi mixey.

i have/had a similar issue. i'm running three 'sites' that need to share users and some date as the three primary navigation sections. this means that editors can be forced to select a menu item from my 'pre-built' tree. it's also probably good to note that i'm doing a brochure site.

site is something like
-site one
-- about
-- stuff1
--- sub one
--- sub two
-- stuff2
-site two
-- about
--- sub one
--- sub two
--- sub three
-- another section

etc, etc.

i'm using url aliases to acces all sections of the site. this is the important part. therefore i can use the following function.


function getLeftNav($node)
{
	// split path into parts
	$pathParts = explode("/", $node->path);

	$menu = menu_get_menu();
	$level2_node_id = drupal_get_normal_path($pathParts[0]."/".$pathParts[1]);
	$menu_id = $menu['path index'][$level2_node_id];
	$output .= theme_menu_tree($menu_id);
	return $output;
}

hope this helps. maybe you've found something more helpful.

mixey’s picture

I was thinking about that. But one thing stoped me.
"Fool proof protection" What if user will forget to enter url alias while creating new content?
Then this solution doesn't make any sence... or I'm wrong?

Anyway thank you for you help!

asparagus’s picture

i am also using path-auto which will automatically create path structures based upon whatever system you enforce. although this could become very complicated to some extent, it does remove the 'oops, forgot the alias' problem.

although my situation involves little access to 'dynamic' or rather content without a previous alias [ ie i'm using all static 'pages' that are updated or aliased 'views' ], there is one other issue that i'm still trying to solve. namely that when using views that provide a preview, the preview url uses not the alias but the internal node/nid path which then doesn't work for me.

anyway, for what it's worth.

good luck.

asparagus’s picture

here's something that might work. it returns an array of all items in the current active path back to the primary menu. you should then be able to pick the correct array index to find out the section your in. of course you could also grab other info from menu_get_menu if you needed it.

hope this helps. i'm working on it myself.

function asp_menu_get_trail_to_root()
{
	$primary_id = variable_get('menu_primary_menu', 0);
	$trailKeys = _menu_get_active_trail_in_submenu($primary_id);
	$menu = menu_get_menu();
	$output = array();
	foreach ($trailKeys as $value)
	{
		$item = array();
		$item['path'] = $menu['items'][$value]['path'];
		$item['mid'] = $value;
		$output[] = $item;
	}
	return $output;
}
faqing’s picture

It works. Follow Gollyg suggested
http://drupal.org/node/57823#comment-140839

What I did:
add the code into page.tpl.php after the line:
// if ($sidebar_left) {

$localNav = _menu_get_active_trail();
if($localNav[1]) {
    print theme_menu_tree($localNav[1]);
}

Alternative Method: Just use Trim Menu module!!!

You can make drupal do anything you wish for your website.
http://thanhsiang.org/faqing