gerald Posted May 15, 2014 Share Posted May 15, 2014 Hi everybody, I have a main menu item with children. By clicking on the main menu item, automatically the first child should be displayed. How to solve this problem? If a similar question has already been answered - sorry, could´nt find it. Thanks very much. Gerald, Austria Link to comment Share on other sites More sharing options...
owzim Posted May 15, 2014 Share Posted May 15, 2014 either you modify the links while creating the menu, like in this approach: https://processwire.com/talk/topic/4261-parent-pages-and-their-behavior/ or you put this in the template which wraps the child pages: $session->redirect($page->children->first()->url); 4 Link to comment Share on other sites More sharing options...
kongondo Posted May 15, 2014 Share Posted May 15, 2014 (edited) Or if you are lazy like me... This should work as well, I think... $session->redirect($page->child()->url); In some cases, can be a good idea to first check if page actually has children ... if($page->numChildren) $session->redirect($page->child()->url) Oh, and welcome to PW! Edited: corrected code, etc... Edited May 15, 2014 by kongondo 4 Link to comment Share on other sites More sharing options...
owzim Posted May 15, 2014 Share Posted May 15, 2014 Or if you are lazy like me... This should work as well, I think... $session->redirect($page->child->url); Oh, and welcome to PW! Nice shortcut, did not know it existed. But I think it's less expressive =) 1 Link to comment Share on other sites More sharing options...
totoff Posted May 15, 2014 Share Posted May 15, 2014 https://processwire.com/talk/topic/15-how-do-i-create-a-page-that-redirects-to-its-first-child/?p=25 2 Link to comment Share on other sites More sharing options...
gerald Posted May 16, 2014 Author Share Posted May 16, 2014 Thx to all. Simple solution works great. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now