在Magento,我们现在拥有的是,各个产品页面上的面包屑总是根据用户到达页面的方式而变化.例如,如果用户从顶级类别到子类别再到产品一直点击,则面包屑将类似于" 首页>>顶级类别>>子类别>>产品 ".
但是,如果用户直接到达产品页面,例如来自Google查询,则面包屑将只是" Home >> Product ".像这样是不酷的.
即使用户从Google访问该页面,也可以通过在面包屑中添加类别来改善用户体验.并且它肯定会增加每次访问的PV,因为用户可能会点击面包屑中的父类别.
那么有什么方法可以使它保持一致并始终在产品页面上显示类别路径?
我的想法是编辑page/html/breadcrumbs.phtml但我不知道如何仅在产品页面上将痕迹添加到面包屑中.
任何帮助,将不胜感激!
======================================
编辑:总之,无论用户如何到达产品页面,我只希望在产品页面的面包屑中显示类别.无论哪个类别,只要有类别.
有人有任何想法吗?这难吗?
在我的头顶,我将需要编辑面包屑模板,并在其中注入类别,如果没有,它是产品页面....但我不知道如何,我似乎无法找到任何相关的解决方案......
Pal*_*mar 16
用这个替换"app/code/core/Mage/Page/Block/Html/Breadcrumbs.php"中的_toHtml()函数.
protected function _toHtml() {
$cat_id = "";
if (Mage::registry('current_product')) {
$product_id = Mage::registry('current_product')->getId();
$obj = Mage::getModel('catalog/product');
$_product = $obj->load($product_id); // Enter your Product Id in $product_id
if ($product_id) {
$categoryIds = $_product->getCategoryIds();
$cat_id = $categoryIds[0];
}
$category = Mage::getModel('catalog/category')->load($cat_id);
$cat_name = $category->getName();
$cat_url = $this->getBaseUrl().$category->getUrlPath();
}
if (is_array($this->_crumbs)) {
reset($this->_crumbs);
$this->_crumbs[key($this->_crumbs)]['first'] = true;
end($this->_crumbs);
$this->_crumbs[key($this->_crumbs)]['last'] = true;
}
if($cat_id) {
$this->_crumbs['category'.$cat_id] = array('label'=>$cat_name, 'title'=>'', 'link'=>$cat_url,'first'=>'','last'=>'','readonly'=>'');
ksort($this->_crumbs);
$home = $this->_crumbs['home'];
unset($this->_crumbs['home']);
array_unshift($this->_crumbs,$home);
}
$this->assign('crumbs', $this->_crumbs);
return parent::_toHtml();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11013 次 |
最近记录: |