下面是強制的Magento顯示完整的麪包屑,包括通過循環槽每個類別當前產品類別代碼:
©丹尼文斯
<?php
if ($product = Mage::registry('current_product')) {
$categories = $product->getCategoryCollection()->load();
if($categories) {
foreach ($categories as $category)
{
if($category) {
$category = Mage::getModel('catalog/category')->load($category->getId());
break;
}
}
}
$lastCrumbName = $product->getName();
$lastCategoryAdjust = 0;
}
else {
if($category = Mage::registry('current_category')) {
$lastCrumbName = $category->getName();
}
$lastCategoryAdjust = 1;
}
if($category) {
if($path = $category->getPath()) {
$path = explode('/', $path);
$crumbs = array('home' => array('label' => 'Home',
'title' => 'Home',
'link' => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB),
'first' => true,
'last' => false
));
for($i = 2; $i < count($path) - $lastCategoryAdjust; $i++) {
$cur_category = Mage::getModel('catalog/category')->load($path[$i]);
if($cur_category && $cur_category->getIsActive()) {
$crumbs['category' . $path[$i]] = array('label' => $cur_category->getName(),
'title' => $cur_category->getName(),
'link' => $cur_category->getUrl(),
'first' => false,
'last' => false
);
}
}
$crumbs['current'] = array('label' => $lastCrumbName,
'title' => '',
'link' => '',
'first' => false,
'last' => true
);
}
}
?>
感謝傑斯,所以我應該在哪裏把這個片段? breadcrumbs.phtml? view.phtml? –
這段代碼應該被添加到你的breadcrumbs.phtml文件的頂部:app/design/frontend/default/template_name/template/page/html/ –
我想這會增加頁面加載時間,因爲它不必要地循環整個分類路徑,如果這樣做能滿足我的需求,我可以在頁面加載時間上略微增加一些時間,但是請給我一個關於多少的想法?這會給我的網站帶來多大的服務器負擔和加載時間?非常感謝! –