Skip to content

Instantly share code, notes, and snippets.

@bugsysop
Created May 25, 2013 22:45
Show Gist options
  • Save bugsysop/5651027 to your computer and use it in GitHub Desktop.
Save bugsysop/5651027 to your computer and use it in GitHub Desktop.
Create a breadcrumbs for Anchor CMS. Add this function in the theme functions.php file.
/*
Usage:
<?php foreach(mytheme_breadcrumbs() as $uri => $name): ?>
<a href="<?php echo $uri; ?>"><?php echo $name; ?></a>
<?php endforeach; ?>
*/
function mytheme_breadcrumbs() {
$links = array();
// is the current page the home page?
if( ! is_homepage()) {
// get the current page
$page = Registry::get('page');
$links[$page->uri()] = $page->name;
// get parent pages
while($page->parent) {
$page = Page::find($page->parent);
$links[$page->uri()] = $page->name;
}
}
// get the homepage
$home = Page::home();
// use menu friendly property (short name)
$links[$home->uri()] = $home->name;
return array_reverse($links);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment