A long time ago I made a website for a friend with a primary menu on top (primary links) and a custom menu in the content block: each primary menu item showed another menu at the left of the content block.
I fixed this with adding a bit of php code on the correct pages :
$mid = <<correct menu id>>;
print theme('menu_tree', $mid);
This works perfectly, the rest of the page html code and text just went under that php code, and everybody was happy.
Until that friend wanted to edit his pages. Because of the custom php code I didn't enable a TinyMCE editor, because off course that would mess up that php code.
Now I was looking for another method to fix this, preferably outside the pages where I just put the php code in now.
So I tried adding a new block of php code where I check the $_REQUEST["q"] and I print the menu_tree on the right pages.
if ($_REQUEST["q"] == "node/2") {
$mid = 2;
print theme('menu_tree', $mid);
}
elseif ($_REQUEST["q"] == "node/3") {
$mid = 74;
print theme('menu_tree', $mid);
}
elseif ($_REQUEST["q"] == "node/13") {
$mid = 70;
print theme('menu_tree', $mid);
}
This php block was added to the content block, but he showed it at the bottom while it should have been on top with a left float. I tried setting the weight to -10, but that didn't change anything.
I hope my explanation is clear enough, feel free to ask if you need more info.
Comments
Why not just place it
Why not just place it directly in page.tp.php. Also if you use the built in primary/secondary feature you can make each of those menus children of the primary menu items and then simply display the secondary menu.
"Also if you use the built
"Also if you use the built in primary/secondary feature you can make each of those menus children of the primary menu items and then simply display the secondary menu."
Can someone explain me how I do that?
Under "Administer" › "Site
Under "Administer" › "Site building" > "Menus" click "Settings" (tab). Make sure both "Menu containing primary links" and "Menu containing secondary links" point to the same menu (typically called "Primary links").
Now build your primary menu at "Administer" › "Site building" > "Menus" adding items to your primary menu. All the items you add will belong to the primary menu. Some will be parent items (there parent is "Primary menu"), they represent the primary menu, others will be children of these parent items, they will be secondary menu items and will display as the the seconday menu . The secondary menu will show the children of the active primary menu item (because of the first step above). So locally you have a menu that looks something like
So your primary menu will show
Parent A | Parent Band if Parent A is the active primary menu the secondary menu will showChild A-1 | Child A-2.In page.tpl.php you will need something like
to display the primary links (menu) and something like
to display the secondary links (menu).
hail to nevets!
Thanks a lot man! A very clear explanation, you made me a bit drupal wiser now.
fwiw, if you want to expose
fwiw, if you want to print an entire region to a template file other than page.tpl.php (so that you could e.g. expose menus and any other blocks you want to the UI for printing in a node's "content" div, but still keep them hidden from the node editing screen), you can use the "Inline regions" technique mentioned on the theme developer's guide Regions in PHPTemplate page.
and a question for nevets...
you can easily pick a "child" menu and only display that menu, but is there a way to turn off display of the children in the parent menu? (e.g., in your example above, if the primary menu is printed the menu items would always be expandable to show their child menu items, correct?)
i've been working under this assumption for some time, but would love to find some UI option or function argument i'm missing to disable display of children altogether, so you could have one hierarchical menu with submenus, but display them separately.
Primary menu always shows
Primary menu always shows just one level if using something like
theme('links', $primary_links, array('class' => 'nav'));hot damn. thanks, nevets.
hot damn. thanks, nevets. i will give it a shot.
cool.. another question for nevet pls..
hello.. this has gotten my attention. you said that Primary menu always shows just one level if using something like theme('links', $primary_links, array('class' => 'nav')); ...... what if i want to show the child of my primary links without using the secondary links (which was explained to codemann right)..since i have a secondary links separated, i want to display the childs of the primary by hovering it. i already configured my menus in the administer section but childs dont come out.. im using d6.. i would appreciate if you can explain in simple terms or show the codes.. thank you very much guys...actually this is really my first time to post comment in such a forum.. ,"
If I understand your
If I understand your question correctly given a menu like
when hovering over 'item 1' you want to see 'item 1-a', 'item 1-b', 'item 1-c' and when hovering over 'item 2' you want to see 'item 2-a', etc. If this is the case a start point is all the items need be in the primary menu to establish the relations between parent and child. The next part, support for the hovering over the links is not part of Drupal core and I am not aware of a module that does that. It would require both a theme function (to output approriate html) and js code to support the hovering.
Hovering in menu
The module "nice_menus" 6.x-1.1 does just the right thing! It drops second-level items to the left or to the right when hoovered over primary-level items. Can be personalized for color etc.