How to make last breadcrumb item as text, not link?

Hi, I am using this method to show breadcrumbs:

<nav class="breadcrumb" role="navigation">
  <ul>
    <?php foreach($site->breadcrumb() as $crumb): ?>
    <li>
      <a href="<?= $crumb->url() ?>">
        <?= html($crumb->title()) ?>
      </a>
    </li>
    <?php endforeach ?>
  </ul>
</nav>

Works nice, only last item is the same as current page, and showing as link. I would like to show it as text, not as link. Logic is that link won’t link to itself.

<?php $crumbs = $site->breadcrumb(); ?>
<nav class="breadcrumb" role="navigation">
  <ul>
    <?php foreach($crumbs as $crumb): ?>
   <?php if ($crumb->isLast()): ?>
    <li>
      <?= $crumb->title()->html() ?>
    </li>
   <?php else: ?>
   <li>
      <a href="<?= $crumb->url() ?>">
        <?= $crumb->title()->html() ?>
      </a>
    </li>
    <?php endif ?>
    <?php endforeach ?>
  </ul>
</nav>

Thanks, tried it, as I understand, it is showing last breadcrumb item as text, when it’s only last child page, but for the rest still as link.

It should show the last crumb item as text. Isn`t that what you wanted?

Yes, I would like to show last breadcrumb item as text, but with that code it’s showing not all last items as text, but only if child page is last. Here is how it works: https://take.ms/fTHdv

Last breadcrumb as text is only working for these pages (green):
breadc

But should be as text for any page, if it’s last in breadcrumb.

Like in https://getkirby.com/docs/cookbook/templating/menus#breadcrumb-menu:

In @texnixe’s code change ->isLast() to ->isActive().

1 Like

I see, thank you, now it’s working.

@HeinerEF @texnixe

$site->breadcrumb()> returns Pages collection but $crumb->isFirst() not working?