Breadcrumbs in frontend -how to edit?

Hey folks.

I´m creating my new site with Kirby. Now I want to include breadcrumbs on the frontend. I´m using this snippet:

`<ul>
<?php foreach($site->breadcrumb() AS $crumb): ?>
<li<?php e($crumb->isActive(), ' class="is-active"') ?>> | <a href="<?php echo $crumb->url() ?>"><?php echo $crumb->title()->html() ?></a></li>
<?php endforeach; ?>
`

Unfortunately those breadcrumbs are not the best way to put it on the frontend. I would like to change the first name “home” into “start”. The first item should have a rel=“home” in the h-ref. Also the last item should not be a link, just the name of the current site.

Did someone know how to get these changes?

If you want home to be called Start, change the title of the home page.

To add the rel attribute for the home page:

<a href="<?php echo $crumb->url() ?>" <?php if($crumb->is(page('home'))) {echo 'rel="home"';} ?>>

As regards the last requirement, you could check if the $crumb has children or not and output the link depending on that condition.

1 Like

Thanks for your reply.
If I placed your snippet into the breadcrumb snippet you cant open the site anymore.

Sorry, I forgot a closing curly brace, added it above.

Please turn on debugging in your (localhost) config.php while developing to get error messages for such cases:

c::set('debug', true);

Okay, thanks for this hint.

I add a missing ). It works fine so far.

<a href="<?php echo $crumb->url() ?>" <?php if($crumb->is(page('home'))) {echo 'rel="home"';} ?>>

What is “the vanilla install”?

It works fine so far.

@RushmerIO refers to the standard Kirby setup, where home is called home (i.e. you haven’t changed this setting in config using c::set('home', 'someOtherPage')) and does not have children.

Is there a way to show the number of the child?

i.e:
Start -> level 1 -> level 2 -> level 3

Those numbers in a seperate variable?

Goal is to show each level a number

<?php echo $crumb->NUMBER() ?>

Yes, you can use the depth() method:

echo $crumb->depth();

Note that is starts with zero, to have it start with 1, you need to add plus 1.

Thank you.
It´s starts with 1 and the next level also get a 1. Third level gets a 2.

i.e.: Start 1 -> level 1 -> level 2

What did I wrong?

Ah, ok, sorry, I was mistaken. Since home is on the same level as any other main page in the file system, these pages are on the same level. To avoid that, you could deduct 1 from the depth for the home page or add 1 for all other pages.

Yes, thats it - thank you very much.

So for all out there who wants to set breadcrumbs with the right richsnippets based on schema.org.

`


    <?php foreach($site->breadcrumb() AS $crumb): ?>
    <li itemprop=“itemListElement” itemscope itemtype=“http://schema.org/ListItem” <?php e($crumb->isActive(), ' class="is-active"') ?>>
    <a href="<?php echo $crumb->url() ?>" itemprop=“item” <?php if($crumb->is(page('home'))) {echo 'rel="home"';} ?>><?php echo $crumb->title()->html() ?>


    <?php endforeach; ?>
` It´s the usual way to set breadcrumbs in kirby (https://getkirby.com/docs/cheatsheet/site/breadcrumb), but with the rich snippets from schema.org. With a little help of the kirby forum. Thanks for that :slight_smile:

For anyone who wants to know how to implement this as JSON schema, this does the trick. You will have to tweak the image call to something you have (or omit that line, i believe image is optional):

<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
<?php
foreach ($site->breadcrumb() as $crumbs):
$index = $site->breadcrumb()->indexOf($crumbs);
$depth = $index + 1;
?>
"position": <?= $depth ?>,
"item": {
"@id": "<?= $crumbs->url() ?>",
"name": "<?= $crumbs->title()->html() ?>",
"image": "<?= $crumbs->articleimage()->toFile()->url() ?>"
}
},<?php endforeach ?>
]
}
</script>