From 0b7a48a52889d0c0683d9c6b77905bc7754d2dbf Mon Sep 17 00:00:00 2001 From: Thomas Threadgold Date: Tue, 24 Oct 2017 11:52:05 +0200 Subject: [PATCH] #10 add option to ignore current page --- breadcrumbs.yaml | 1 + classes/breadcrumbs.php | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/breadcrumbs.yaml b/breadcrumbs.yaml index b6814af..5364d9d 100644 --- a/breadcrumbs.yaml +++ b/breadcrumbs.yaml @@ -2,6 +2,7 @@ enabled: true show_all: true built_in_css: true include_home: true +include_current: true icon_home: '' icon_divider_classes: 'fa fa-angle-right' link_trailing: false diff --git a/classes/breadcrumbs.php b/classes/breadcrumbs.php index e1312ed..1b13078 100644 --- a/classes/breadcrumbs.php +++ b/classes/breadcrumbs.php @@ -44,17 +44,26 @@ protected function build() $grav = Grav::instance(); $current = $grav['page']; - while ($current && !$current->root()) { - $hierarchy[$current->url()] = $current; - $current = $current->parent(); - } - // Page cannot be routed. if (!$current) { $this->breadcrumbs = array(); return; } + if (!$current->root()) { + + if ($this->config['include_current']) { + $hierarchy[$current->url()] = $current; + } + + $current = $current->parent(); + + while ($current && !$current->root()) { + $hierarchy[$current->url()] = $current; + $current = $current->parent(); + } + } + if ($this->config['include_home']) { $home = $grav['pages']->dispatch('/'); if ($home && !array_key_exists($home->url(), $hierarchy)) { @@ -62,7 +71,6 @@ protected function build() } } - $this->breadcrumbs = array_reverse($hierarchy); } }