WebsiteBaker Support (2.8.x) > Templates, Menus & Design
Show menu only on specific pages
flip:
Hello,
I am using the menu2 module and included the menu in the template. I would like to show the menu only on specific pages. The options I came up with:
- Create a separate template: It would mean a lot of more work because I need to keep up-to-date another template just to have one with and the other without sub-menu.
- Use Droplets: Add the menu code to a droplet and add it only to the pages when needed. I haven't tested it but it's also not s9o good for me because then I need to create new placeholder sections
What I am using right now is a hardcoded menu which only shows up when the URL matches specific criteria, e.g. ends with /prices.php. The issue is that the menu is also shown on custom htaccess error pages when you open a not-existing URL which also ends with prices.php. I don't want to show the menu on these error pages.
Do you have a better solution for showing / hiding a sub-menu on each separate page or do you have any suggestion how to avoid showing the menu on the htaccess error pages even though the URL matches?
Thanks,
Philip
Argos:
You can create a hidden menu block and assign pages that menu if you don't want to show the menu. So add a line like
$menu[4] = 'Hidden';
and set the menu to "Hidden" in the page Settings.
I tried it and it works fine, except for 1 thing: it only hides all other pages in the menu, but it still shows the current menu item. So if you hide the page "Products", the site shows a menu with only "Products". But the menu graphics (if you use those) will still be visible. So this solution hides the menu entries, not the menu itself. But it can be useful nevertheless.
Another solution is to hide or show the complete menu according to page ID. Something like this in your template will work:
--- Code: ---<?php
if (PAGE_ID==24 | PAGE_ID==30 | PAGE_ID==45 | PARENT == 24 | PARENT==30 | PARENT==45 ) {
echo "your-menu-call-here";
}
?>
--- End code ---
That way the menu will only show up on pages with ID 24, 30 and 45, and on their child pages. If you want to hide them, instead of show them, use != instead of ==.
marmot:
Hi,
--- Quote ---What I am using right now is a hardcoded menu which only shows up when the URL matches specific criteria, e.g. ends with /prices.php. The issue is that the menu is also shown on custom htaccess error pages when you open a not-existing URL which also ends with prices.php. I don't want to show the menu on these error pages.
--- End quote ---
it's hard to imagine why this doesn't work as the url becomes a new one when redirected. Maybe you can give more information on how redirection and menu creation is done and show an example.
--- Quote ---Do you have a better solution for showing / hiding a sub-menu on each separate page or do you have any suggestion how to avoid showing the menu on the htaccess error pages even though the URL matches?
--- End quote ---
- use page id instead of url to recognize the need of menu
- check url also against table pages to see if page exists
- use banner module
- if pages with or without menu are all on same menu levels you might try to use sm2 call (start and end level) to show/hide menu
regards
flip:
Hello,
Many thanks for the ideas. I will try them.
Regarding the htaccess error page: It's not a redirect but the error page opens under the URL which you opened. Amazon and Zalando work similar:
http://www.zalando.de/jack-jones-clark-original-jeans-dark-dim-ja222x016-953.html
There is no redirect to:
http://www.zalando.de/error404.html
Philip
Argos:
--- Quote from: flip on August 01, 2012, 07:07:49 PM ---Regarding the htaccess error page: It's not a redirect but the error page opens under the URL which you opened. Amazon and Zalando work similar:
http://www.zalando.de/jack-jones-clark-original-jeans-dark-dim-ja222x016-953.html
--- End quote ---
And they do show the menu :roll:
Navigation
[0] Message Index
[#] Next page
Go to full version