WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Templates, Menus & Design => Topic started by: flip on August 01, 2012, 09:41:32 AM

Title: Show menu only on specific pages
Post by: flip on August 01, 2012, 09:41:32 AM
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
Title: Re: Show menu only on specific pages
Post by: Argos on August 01, 2012, 11:07:35 AM
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: [Select]
<?php 
if (PAGE_ID==24 PAGE_ID==30 PAGE_ID==45 PARENT == 24 PARENT==30 PARENT==45 ) { 
echo 
"your-menu-call-here";
}
?>

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 ==.
Title: Re: Show menu only on specific pages
Post by: marmot on August 01, 2012, 11:11:17 AM
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.
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?
- 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
Title: Re: Show menu only on specific pages
Post by: flip on August 01, 2012, 07:07:49 PM
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
Title: Re: Show menu only on specific pages
Post by: Argos on August 01, 2012, 08:48:05 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

And they do show the menu  :roll:
Title: Re: Show menu only on specific pages
Post by: marmot on August 01, 2012, 10:48:40 PM
Hi,

There is no redirect to:
http://www.zalando.de/error404.html
that's fine but how (from the programmers view) is the call for the error page done in your case?

regards
Title: Re: Show menu only on specific pages
Post by: flip on August 02, 2012, 05:41:12 AM
Hello Marmot,

I'm using simple htaccess rules:
ErrorDocument 400 /en/error/400.php
ErrorDocument 401 /en/error/401.php
ErrorDocument 403 /en/error/403.php
ErrorDocument 404 /en/error/404.php
ErrorDocument 500 /en/error/500.php

It's not redirecting to the error pages. The error pages are opened under the link which doesn't exist.

Philip
Title: Re: Show menu only on specific pages
Post by: flip on August 02, 2012, 05:48:12 AM
@Argos: I show the main menu on the error page as well like Zalando does but I don't want to show my sub-menu on these pages.
Title: Re: Show menu only on specific pages
Post by: marmot on August 02, 2012, 10:16:30 AM
Hi,

It's not redirecting to the error pages. The error pages are opened under the link which doesn't exist.
ok, had a small error in my thoughts ;). Besides the possibilities mentioned above it would be possible to do the redirect this way:
Code: [Select]
ErrorDocument 404 /en/error/404.php?redirect=1 and your existing condition for the menu call has to be extended by:
Code: [Select]
&& !isset($_GET['redirect'])
regards
Title: Re: Show menu only on specific pages
Post by: Argos on August 02, 2012, 11:48:42 AM
@Argos: I show the main menu on the error page as well like Zalando does but I don't want to show my sub-menu on these pages.

Try this:

Code: [Select]
<?php 
if (PAGE_ID!=0) { 
echo 
"your-menu-call-here";
}
?>

Or this:

Code: [Select]
<?php 
if (PAGE_ID>0) { 
echo 
"your-menu-call-here";
}
?>

Not tested...
Title: Re: Show menu only on specific pages
Post by: flip on August 03, 2012, 06:03:11 AM
Thank you for all the suggestions. I hard-coded several of them (Page IDs, URL parameters in htaccess error pages, etc.) and it works great!