Jump to content
Sign in to follow this  
adrianmak

how to make a parent menu item without linking to a page ?

Recommended Posts


Home
  +--menu-1
        +---menu-1-1
        +---menu-1-2
        +---menu-1-3
        +---menu-1-4
  +--menu-2
        +---menu-2-1
        +---menu-2-2
        +---menu-2-3
  +--menu-3
  +--menu-4

menu-1 and menu-2 which are associated to a page, but without content.

It just a sub-menu holder, click menu-1, or menu-2 to expand it's child menu

how to make clicking of menu-1 and menu-2  without opening menu- and menu-2 page ?

Share this post


Link to post
Share on other sites

In these cases I'd give the pages menu-1 and menu-2 a template, consisting of:

<?php
/**
 * Template: First Child redirect
 *
 */

if($page->numChildren) $session->redirect($page->child()->url);

So that a click on them redirects to menu-1-1 or menu 2-1 respectively.

More: https://processwire-recipes.com/recipes/quick-first-child-redirect/

Share this post


Link to post
Share on other sites

You should take care of that in your menu generating code, so that menu-1 and menu-2 are somehow recognizable for the needed javascript and not link to a page.

You can hardcode it or take an approach like https://processwire.com/talk/topic/4261-parent-pages-and-their-behavior/

You should also decide what you show when you manually go to the container url, see some options in the above thread.

  • Like 1

Share this post


Link to post
Share on other sites

in your custom menu pages, you just need to have a menu override.

post-136-0-69088200-1428581901_thumb.png

Share this post


Link to post
Share on other sites

you just make a custom menu tree using a menu type template...

Thank you for redirect to your post.

I have a few questions not quit understood/clear of your custom menu tree implementation.

1. the 'Main Menu' page tree is a separate tree from the site root or still under a child of the site root ?

2. Isn't the 'Main Menu' structures are inputted manually one by one ?

Share this post


Link to post
Share on other sites

ok - so for the custom menu, the way i did it in the past on many sites was with a hidden branch of the page tree, usually underneath a page called Settings;

Most sites i build do require the menu to be very specific and there is absolutely no way that the menu displayed in the front end can be based on the page tree;

in my opinion, the page tree being used as the front end menu is only for very small and simple sites; anything more complicated requires you to build your own menu, and now that we have Kongondo's menu module, this is even easier than ever.

If you take a look at that module, there may very well be a way to assign a custom URL override to any menu item; i have not tried it yet, but i am planning on using it for the next site i release which is now in admin development.

once you have made your menu page tree (yes manually, one by one), and on each of those items selected the page that the menu item will link to, you can use that code to output your menu, and modify it to your needs in terms of menu markup. You can also configure the override field to be always used if it is populated.

If you wish to use the page tree as-is to generate your menu, that is pretty much the same thing; you just need a field to override the page's URL in the menu and then use your output code to check if that field is populated and swap out the value of that field with the default URL of the page.

  • Like 2

Share this post


Link to post
Share on other sites

Most sites i build do require the menu to be very specific and there is absolutely no way that the menu displayed in the front end can be based on the page tree;

in my opinion, the page tree being used as the front end menu is only for very small and simple sites; anything more complicated requires you to build your own menu, and now that we have Kongondo's menu module, this is even easier than ever.

If you take a look at that module, there may very well be a way to assign a custom URL override to any menu item; i have not tried it yet, but i am planning on using it for the next site i release which is now in admin development.

Currently this is possibly only with Custom Menu Item (external links) where you can provide # as a URL. At the moment, PW pages' URLs are non-editable but I can easily provide an option to make them editable if such a feature was requested (preferably via Github)..

Share this post


Link to post
Share on other sites

Currently this is possibly only with Custom Menu Item (external links) where you can provide # as a URL. At the moment, PW pages' URLs are non-editable but I can easily provide an option to make them editable if such a feature was requested (preferably via Github)..

that sounds like it would be perfect and exactly what i was hoping for!

i can't think of any reason to edit the PW urls; the external link option should be all that is needed; i'll be testing your module over the next week and will report back on that topic.

i think for adrianmak's usage, the menu builder module would be a time saver over doing it the old way with page tree, or using a field on the page to override the page's url for menu purposes.

Share this post


Link to post
Share on other sites

that sounds like it would be perfect and exactly what i was hoping for!

i can't think of any reason to edit the PW urls; the external link option should be all that is needed;....

You are right...would certainly make life easier....Just Create a 'dummy link' and bob's your uncle.... :D...I could then focus on other pending modules :-)

Share this post


Link to post
Share on other sites

that sounds like it would be perfect and exactly what i was hoping for!

i can't think of any reason to edit the PW urls; the external link option should be all that is needed; i'll be testing your module over the next week and will report back on that topic.

i think for adrianmak's usage, the menu builder module would be a time saver over doing it the old way with page tree, or using a field on the page to override the page's url for menu purposes.

Kongondo just pointed out that pw's url is not editable. Isn't the custom menu override url option is just for menu markup prupose, but it's not really override page's url

Share this post


Link to post
Share on other sites

not sure what you mean.. we are making a menu right? so all that matters is the url you want on the menu item, and that is markup.

the URL override in my example means that if a URL is entered into that field, it overrides anything selected in the page select. It has nothing to do with processwire pages at all..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...