Hey there.
I want to create an off-canvas menu, including all visible pages below $site, their children and grandchildren.
This is what I have:
<?php
$items = $site->children()->visible();
if($items->count()) :
?>
<nav class="off-canvas position-right" id="offCanvasRight" data-off-canvas data-transition="overlap" data-content-scroll="false">
<ul class="vertical menu" data-accordion-menu data-multi-open="false">
<?php foreach($items as $item) : ?>
<li>
<a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>">
<?= $item->title()->html() ?>
</a>
<?php
$items = $item->children()->visible();
if($items and $items->count()):
?>
<ul class="nested menu vertical<?php e($item->isOpen(), ' is-active') ?>">
<?php foreach($items as $item) : ?>
<li>
<a<?php e($item->isOpen(), ' class="is-active"') ?> href="<?= $item->url() ?>">
<?php if($item->volume()) : ?>
Vol. <?= $item->volume() ?>, Nr. <?= $item->number() ?> <?php e($item->number()->int() == 1, '(Winter ', '(Summer ') ?><?= $item->date('Y', 'year') ?>)
<?php else : ?>
<?= $item->title()->html() ?>
<?php endif ?>
</a>
<?php
$items = $item->children()->visible();
if($items and $items->count()):
?>
<ul class="nested menu vertical<?php e($item->isOpen(), ' is-active') ?>">
<?php foreach($items as $item) : ?>
<li>
<a<?php e($item->isOpen(), ' class="is-active"') ?> class="accordion-title" href="<?= $item->url() ?>">
<?= $item->title()->html() ?>
</a>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
</nav>
<?php endif ?>
However, what I am not getting is this: I want to change the displayed link text for every item on the second level that meets certain criteria (doesn’t matter which one I choose, be it template (the second-level items I’m targeting are the only pages with that specific template), parent (the second-level items I’m targeting are the only children of that specific parent), …), BUT I don’t know HOW to address or target them correctly - It only works if I am not currently browsing on these second-level items’ pages or one of their children …
// Edit:
The code above shows <?php if($item->volume()) : ?>
, but that’s only one approach I tried … volume() is a field only the pages I am targeting has …