在Magento的各个产品页面上制作一致的面包屑? [英] Making consistent breadcrumbs on individual product pages in Magento?

查看:56
本文介绍了在Magento的各个产品页面上制作一致的面包屑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Magento中,我们现在所拥有的是,各个产品页面上的面包屑总是根据用户到达页面的方式而变化.例如,如果用户一直单击从顶部类别到子类别然后再到产品的路径,则面包屑将类似于"首页>>顶部类别>>子类别>>产品".

In Magento, what we have now is that the breadcrumbs on individual product pages are always changing according to how the user has arrived at the page. For example, if user clicked all the way from top category to sub category and then to the product, the breadcrumbs would be something like "Home >> Top category >> Sub category >> Product".

但是,如果用户直接访问产品页面(例如通过Google查询),则面包屑将仅仅是"首页>>产品".像这样真是太不可思议了.

However if the user arrives at the product page directly, such as from Google queries, the breadcrumbs would simply be "Home >> Product". And it is uncool to be like this.

即使用户从Google到达网页,也可以通过在面包屑中添加类别来绝对改善用户体验.而且肯定会增加每次访问的PV,因为用户可能会点击面包屑中的父类别.

It would definitely be a user experience improvement by adding categories in the breadcrumbs even when the user arrives at the page from Google. And it would definitely increase PV per visit because users will likely to click on parent categories in the breadcrumbs.

那么有什么方法可以使其保持一致并始终在产品页面上显示类别路径?

So is there any way to make it consistent and always show the categories path on product pages?

我的想法是编辑page/html/breadcrumbs.phtml,但我不知道如何仅在产品页面上为面包屑添加类别.

My idea is to edit page/html/breadcrumbs.phtml but I don't know how to add categories to the breadcrumbs only on product pages.

任何帮助将不胜感激!

====================================

======================================

总而言之,无论用户如何到达产品页面,我都只希望类别出现在产品页面的面包屑中.不管哪个类别,只要存在这些类别即可.

In a word, I just want categories to appear in the breadcrumbs on product pages no matter how the user arrives on the product page. Doesn't matter which categories, as long as the categories are there.

有人知道吗?这很难吗?

Anyone got any idea? Is this that hard?

在我的头顶上,我将需要编辑面包屑模板,并在其中插入类别(如果没有),这是产品页面....但是我不知道该怎么做,我可以.似乎在任何地方都找不到与此相关的解决方案...

Off the top of my head, I will need to edit the breadcrumbs template and inject the categories in it if there aren't any and it's the product page....but I don't know how and I can't seem to find any relevant solutions to this anywhere...

推荐答案

用此代码替换"app/code/core/Mage/Page/Block/Html/Breadcrumbs.php"中的_toHtml()函数.

Replace _toHtml() function in "app/code/core/Mage/Page/Block/Html/Breadcrumbs.php" with this one.

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();
}

这篇关于在Magento的各个产品页面上制作一致的面包屑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆