caplod
1
I have a menu where I want to include a link to a specific subpage on the parent menu.
- 01-Home
- 02-Products
- <-- here link to Subpage 2
- 03-News
- Section
– Subpage 1
– Subpage 2
- Error
- Privacy
in the docs I found this: https://getkirby.com/docs/cookbook/simple-redirects but thats a redirect.
I want to have the direct link to Subpage 2.
Any ideas?
texnixe
2
There are several ways to do that.
- You could - within your loop stop after the first two and then manually insert the link to the subpage.
- you could use a built-in field or custom field to build a custom menu
- …
<nav>
<ul>
<?php foreach($items->limit(2) as $item): ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><?= $item->title()->html() ?></a></li>
<?php endforeach ?>
<?php if($subpage = page('path-to-subpage'): ?>
<li><a<?= $subpage->url() ?></a></li>
<?php endif ?>
<?php foreach($items->offset(2) as $item): ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><?= $item->title()->html() ?></a></li>
<?php endforeach ?>
</ul>
</nav>
caplod
3
Thanks for the hint!
Because the subpage always needed to be below products I did this:
<ul class="nav">
<?php foreach($pages->visible() as $item): ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?php echo $item->url() ?>"><?php echo html($item->title()) ?></a></li>
<?php if(($item->uri() == 'products') && ($subpage= page('path-to-subpages'))): ?>
<li><a<?php e($subpage->isOpen(), ' class="active"') ?> href="<?php echo $subpage->url() ?>"><?php echo html($subpage->title()) ?></a></li>
<?php endif ?>
<?php endforeach ?>
</ul>