Posted by futurist on September 4, 2007 at 3:40pm
Is there any way to keep a menu expanded (so that all of its items are shown), even if one is viewing a page that is not a child of that menu? For example:
Menu
- Item 1 (URL 1)
- Item 2 (URL 2)
Search page (URL 3 - currently viewing)
Items 1 and 2 of Menu should be visible when viewing URL 3. Can this be solved by a custom function in template.php? I've seen that a URL can be mapped to a function without creating a visible menu item but I don't know if that can solve this problem.
Thanks for any help!
Comments
Expanding a menu
If you edit a menu item – the parent of the items that you want to be shown – click the tick-box marked Expanded and save (submit) it, you should get the desired effect.
NB this doesn’t work for displaying the children of a #primary menu item in the #secondary menu.
___________________
It’s in the detaιls…
The problem is more complex...
Thanks zeta-zoo. I see that I need to describe my situation in more detail to show the problem. I have:
Shop
- Guitars
- Amps
Service
- Guitar Repair
- Amp Repair
Search page (currently viewing, not in menu, "Shop" should be expanded)
When I follow your suggestion ("Shop": expanded), then its children "Guitars" and "Amps" always show, even when I go to "Service". (When setting the parent item "Service": expanded at the same time, the children "interfere".)
However, what I need is:
Try this...
Add another item as a child of Shop, that points to the Search page — then disable it.
Success might depend on the exact address of the Search page, but if there is no other items in that menu that are similar, it should work.
___________________
It’s in the detaιls…
Doesn't work...
I tried — but it doesn't work, even though I set the path exactly to the address of the page (including slashes). (Then, I'm not surprised it doesn't work; after all the item is disabled.)
Maybe there is a different approach to this using an override function in template.php? Or a module (perhaps Menu Trails)?
Don't give up...
I’m not guessing… I have tried it, and it does work :o
Being disabled is not the problem here.
node/search(or whatever points to the search page)?I don’t see the point of using an override function, or a module when the menu system is already capable of doing this.
——————————————___________________
It’s in the detaιls…
Didn't give up — and finally got it working
Thanks a bunch, zeta-zoo! These were some very useful points to look at:
It is created by the Views module. The view provides a page, and I had to tell it to also provide a menu entry. I set the path to search_product in the view.
No, the search page doesn't. The view just exposes a filter (search form) in a block. But I have other pages (some created by views, some by nodes) which have menu items in another menu (call it Submenu) and which should make the Shop menu expand. For those pages, this is what happened:
I created an entry called {Page XY} (Dummy) and disabled it. This alone didn't work. I had to delete the previously existing entry that points to the {page XY} in Submenu and then re-create it exactly as it was! What difference does that make? The newly created entry in Submenu has a different id (before: 165, now: 260). The id of the disabled dummy in the Shop menu is 259.
My bottom lines:
Can this be true? (#2 looks eerie to me...)
P.S.: Never meant to suggest you were just guessing — I guess I was just a bit desperate. Very much appreciate your help.
P.S.2: I absolutely second that. Knowing Drupal only since a couple of months, I just find it very difficult sometimes to determine what it can do out of the box (e.g.: can images be inserted into blog posts? — not with core modules), or whether it's better to plug in a module (and learn how to use it) or write some custom code in template.php (which i'm often more comfortable with).
“∴ —”…
Cool. Glad I wasn’t going mad.
#2 does look a bit weird, but could be due to iterating through a list and assuming (understandably) that there’s only one. Will have to look at the code.
I’ve been trying for months to put entities in the title of these comments – why didn’t I think of copy&paste before? Is that how you did it?
___________________
It’s in the detaιls…
:—)
Let me know what you find, please. Btw. the menu items provided by views don't seem to interfere with disabled dummy menu items the same way manually created entries do.
copy&paste? Yes!
Couldn’t find anything
Couldn’t find anything in the code but these might be of interest…
Child menus
Expanded menus don't stay expanded
Expanding a menu tree based on node types
___________________
It’s in the detaιls…
It is true
Just tried it and I can confirm, that the way described above works also when a menu item does not expand as expected. This usually happens when you have a multi language website, with all menu items for individual language homepage pointing to <front>. This leads to a problem, when the menu expands only on one of the language homepages, on the other language versions the homepage menu items do not expand.
Then you need to make two menu items for such homepage:
1. The menu item created later (has a higher id in the database) must be the visible parent (that shall be expanded).
2. The menu item created earlier (has a lower id in the database) must be the hidden child (that makes the parent expand).
Both menu items have to point to respective node/{id} (i.e. node/1 in Czech and node/15 in English), not to <front>, in all languages!
This brings up a new problem of having duplicate content for homepage on more than one URL, which I decided to solve using Global Redirect module.
So it obviously has something to do with database order of menu items. Thank you so much for a suggestion, I have been fighting with this for ages.