Thanks. I’ll try that, I discovered something else odd though. On my “about” page which uses a redirect template the isChildOf works just fine, but on my other pages it doesn’t. Here’s my menu as it stands right now:
This was all working as expected before the Kirby 3 update:
<?php if ($page->id() != 'home'): ?>
<ul itemscope itemtype="https://schema.org/SiteNavigationElement" class="menu">
<?php foreach($pages->listed() as $p): ?>
<li>
<?php if ($p->id() == 'about'): ?><br><?php endif ?>
<h4 itemprop="name">
<?php if(($p->isActive()) or ($page->isChildOf($p))): ?><span class="dark"><?php endif ?><a href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a></span>
</h4>
<?php
// get all children for the current menu item
$children = $p->children()->listed();
// display the submenu if children are available
if($children->count() > 0):
?>
<?php if($page->template() == 'redirect' || $page->parent()->template() == 'redirect'): ?>
<?php if(($p->isActive()) or ($page->isChildOf($p))): ?>
<ul class="indent">
<?php foreach($children as $child): ?>
<li itemprop="name"><a<?php e($child->isOpen(), ' class="dark"') ?> href="<?= $child->url() ?>"><?= $child->title()->html() ?></a></li>
<?php endforeach ?>
</ul>
<?php endif ?>
<?php endif ?>
<?php if($page->template() == 'work_portal' || $page->parent()->template() == 'work_portal' || $page->parent()->template() == 'series_visual'): ?>
<?php if(($p->isActive()) or ($page->isChildOf($p))): ?>
<ul class="indent">
<li itemprop="name">
<a <?php
$urllinked = (page('work')->url() . '/type:sonic');
if ($urlactive == $urllinked)
echo 'class="dark"';
?>
href="<?= page('work')->url() ?>/type:sonic">Sonic Work</a></li>
<li itemprop="name">
<a <?php
$urllinked = (page('work')->url() . '/type:visual');
if ($urlactive == $urllinked)
echo 'class="dark"';
?>
href="<?= page('work')->url() ?>/type:visual">Visual Work</a></li>
<li itemprop="name">
<a <?php
$urllinked = (page('work')->url() . '/type:constellation');
if ($urlactive == $urllinked)
echo 'class="dark"';
?>
href="<?= page('work')->url() ?>/type:constellation">Constellations</a></li>
</ul>
<?php endif ?>
<?php endif ?>
<?php endif ?>
<?php endforeach ?>
</li>
</ul>
<?php endif ?>
What this was doing in Kirby 2 was, if there were children for the menu item it would show them if you were on the page or one of its children or grandchildren, and if the child was active or one of its ancestors was active then it would highlight the child in the menu, which seemed to work with just parent-> in the old version.
I’ll take a stab at reworking this then and try to figure out a fix.
I see. So I should change that in the Kirby core? I changed it on the template where I was calling for the parent template and that didn’t fix anything.
Okay, well if I just remove the isChildOf($p) statements then the menu works again. The parentModel() seems to work for testing which templates the pages belong to, but this is still persisting.
I can change the color of the menu item if the menu’s first-level page with isOpen() , but I’d like to keep the color of the menu item changed if the visitor then navigates to one of the children of the menu item.
Okay. I’ll give this a try, thanks so much for your help.
For most of the site I only want first-level pages as the menu items, but each of the first-level pages has many children, basically I have several different article sets in different sections and I still want the visitor to know which section they’re in.