Jump to content

Navigate Markup issue


Jon
 Share

Recommended Posts

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

? $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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...