I’m trying to create a subnav header for a specific page template. However, when I run a forloop to create the main nav
<nav>
<?php if(!$page->isHomePage()): ?>
<a href="<?= $site->url() ?>"> Home </a>
<?php endif ?>
<?php
$pages = $site->children()->listed();
foreach($pages as $page): ?>
<a href="<?= $page->url() ?>"> <?php echo $page->title() ?> </a>
<?php endforeach ?>
</nav>
This spits out:
- Home
- Contributions
- Resources
- About
Now, any attempt to access the specific page information in the code after the nav like so:
</nav>
<?= $page->url() ?>
Is only giving me the URL and template information of the ‘about’ page like: https://localhost/critical-code-cookbook/about
However, when I put the code before the nav like so:
<?= $page->url() ?>
<nav>
This gives me the actual page’s information: https://localhost/critical-code-cookbook/contributions/house-of-words
I’ve attached an image below showcasing the issue.
Is there something wrong with my setup for the navigation?