I'm a bit of a novice at this but here goes.
I have two page types - CategoryPage and ProductPage, where a ProductPage has a single relationship to a CategoryPage type.
Instead of displaying the breadcrumb from where the ProductPage is within the SiteTree, I want to use the CategoryPage that is related to the ProductPage and use this in breadcrumb.
So instead of Home > ProductHolder > ProductPage, it should instead display Home > CategoryPage > CategoryPage > ProductPage.
I have created (well actually copied and modified from SiteTree.php) the following code where the main changes has been at the end of the while loop where it checks the page type. Its not breaking but its not showing the category path back to the home page either (ie it only shows Home > ProductPage).
public function LoadedBreadcrumbs($maxDepth = 20, $unlinked = false,
$stopAtPageType = false) {
$parts = array();
$i = 0;
$page = $this;
while(($page && (sizeof($parts) < $maxDepth)) ||
($stopAtPageType && $page->ClassName != $stopAtPageType)) {
if($page->ShowInMenus || ($page->ID == $this->ID)) {
if($page->URLSegment == 'home') {
$hasHome = true;
}
$parts[] = (($page->ID == $this->ID) || $unlinked)
? "<li>" . Convert::raw2xml($page->Title) . "</li>"
: ("<li><a href=\"" . $page->Link() . "\">" . Convert::raw2xml($page->Title) . "</a> > </li>");
}
if($page->ClassName == "ProductPage"){
$category = $page->CategoryID;
$filter = "`SiteTree_Live`.ID = $category";
$page = DataObject::get('CategoryPage',$filter);
} else {
$page = $page->Parent;
}
}
return implode(self::$breadcrumbs_delimiter, array_reverse($parts));
}
Can anyone help with switching from one page type to another related page type in breadcrumb? Thanks in advance....