Hello.
I try to modify a breadcrumb to list only elements in the current subfolder and it’s subfolders.
The original code below.
<nav class="breadcrumb">
<ul>
<?php $x = 1; foreach($site->breadcrumb() as $crumb_key => $crumb): ?>
<li<?php e($crumb->isActive(), ' class="is-active"') ?>><a href="<?php echo $crumb->url() ?>"><?php echo $crumb->title()->html(); echo $x != count($site->breadcrumb()) ? ' ›' : ''; $x++ ?></a></li>
<?php endforeach; ?>
</ul>
</nav>
How can I achieve this with code like this?
<?php if($crumb->is(page('blog'))) continue; ?>
The breadcrumb method returns a child collection, so you should be able to find a special page by uri within this children collection.
In this way you can check if the blog page is part of the breadcrumb and then display the breadcrumb (untested):
<?php if ($site->breadcrumb()->find('blog')): ?>
<nav class="breadcrumb">
<!-- your breadcrumb code -->
</nav>
<?php endif; ?>
texnixe
3
Hm, I’m not quite sure, looks like you want to exclude the blog page but display the children etc.?
Then you could use not()
like this:
<nav class="breadcrumb">
<ul>
<?php $x = 1; foreach($site->breadcrumb()->not('blog') as $crumb_key => $crumb): ?>
<li<?php e($crumb->isActive(), ' class="is-active"') ?>><a href="<?php echo $crumb->url() ?>"><?php echo $crumb->title()->html(); echo $x != count($site->breadcrumb()) ? ' ›' : ''; $x++ ?></a></li>
<?php endforeach; ?>
</ul>
</nav>
texnixe
Split this topic
4
2 posts were split to a new topic: Exclude pages in treemenu