在Magento中,当用户直接访问产品页面时,例如从谷歌,面包屑将只是“主页”->“产品名称”。
How can I add categories in there even when users access the page directly from Google?
例如,在this page上,我想在面包屑中添加类别“婚纱”和“婚纱”。我想出了一个不是硬编辑breadcrumbs.phtml的想法,但是有没有办法通过编程在模板/目录/产品/视图.phtml中添加一个breadcrumbs项?
我可以获得当前产品的类别(标题和链接),然后使用一些函数/方法动态地以编程方式将它们添加到面包屑中。这个是可能的吗?
发布于 2012-09-26 01:40:11
以下代码强制Magento显示完整的breadcrumb,包括通过循环遍历当前产品的每个类别的类别:
©丹尼·文斯
<?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
);
}
}
?>https://stackoverflow.com/questions/12576614
复制相似问题