Typical breadcrumbs example

Problem

You want to create a typical breadcrumb list, with last item not linked and showing the current page

Solution

echo "<ul class=\"breadcrumbs \">";

$parents = $page->parents;

foreach($parents as $parent) {
    $url = $parent->url;
    echo "<li><a href='$url'>{$parent->title}</a></li>\n";
}

// show current / "we are here" page as well, but not as link: (last element)
echo "<li>{$page->title}</li>\n";

echo "</ul>";

Resources

Version

1.0.1

View/correct recipe on GitHub

https://github.com/processwire-recipes/Recipes/blob/master/typical-breadcrumbs-example.md

Author(s)