Jon Posted October 25, 2023 Share Posted October 25, 2023 Hello, I am putting together a navigation bar using $pages->get('/')->children which works, however if I visit the childpage of any page that has grand Children the navigation bar disappears because $pages->get('/')->children is returned empty any ideas? Full code below foreach ($pages->get('/')->children as $childPage): ?> <?php if ($childPage->hasChildren && $childPage->template != "news"){ ?> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="dropdown-<?= $childPage->id; ?>" role="button" data-bs-toggle="dropdown" aria-expanded="false"> <?= $childPage->get("nav_text|title"); ?> </a> <ul class="dropdown-menu" aria-labelledby="dropdown-<?= $childPage->id; ?>"> <?php foreach ($childPage->children as $subPage): ?> <li><a class="dropdown-item" href="<?= $subPage->url; ?>"><?= $subPage->get("nav_text|title"); ?></a></li> <?php endforeach; ?> </ul> </li> <?php }else {?> <li class="nav-item"> <a class="nav-link" href="<?= $childPage->url; ?>"><?= $childPage->get("nav_text|title"); ?></a> </li> <?php }; endforeach; ?> Link to comment Share on other sites More sharing options...
virtualgadjo Posted October 26, 2023 Share Posted October 26, 2023 hi, have you tried $pages->get(1) instead of get->('/')? 1 being the id of the homepage, if the problem stays the same it more a case of where that nav is placed in your templates structure have a nice day 1 Link to comment Share on other sites More sharing options...
Jon Posted October 26, 2023 Author Share Posted October 26, 2023 Ah thank you, I had used $pages as a variable else where in the template for the parent pages doh. Thank you! Link to comment Share on other sites More sharing options...
virtualgadjo Posted October 26, 2023 Share Posted October 26, 2023 ? $pages is a very useful var but it may be sometimes tricky particularly when dealing with multilingual websites (4 out of five websites in my case being a froggy... ? ) i always use this module https://processwire.com/modules/page-list-show-page-id/ as dealing with page ids allows us to make really short an efficient requests with $pages->get, pw taking care of the language of the object you retreive have a nice day 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