Breadcrumbs are very useful for user navigation. Breadcrumbs for product page, category page, etc. are created by default Magento code.
?
The following code will show breadcrumbs created by Magento. You can print the following code anywhere in php or phtml files.
echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();?
You can create you own breadcrumbs as well. Like, you may need to create breadcrumbs if you have your own custom built module. I will show you here, how you can do it.
?
It’s simple and easy. At first, you will define the breadcrumbs block. Then, you will add label, title and link to your breadcrumbs. The addCrumb Magento function is used in this case.
$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); $breadcrumbs->addCrumb('home', array('label'=>Mage::helper('cms')->__('Home'), 'title'=>Mage::helper('cms')->__('Home Page'), 'link'=>Mage::getBaseUrl())); $breadcrumbs->addCrumb('country', array('label'=>'Country', 'title'=>'All Countries', 'link'=>'http://example.com/magento/moduleName/country')); $breadcrumbs->addCrumb('manufacturer', array('label'=>'State', 'title'=>'States')); echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();?
The label, title and link can be changed according to your need and requirement.
Hope this helps. Thanks.
?
來源: http://blog.chapagain.com.np/magento-easily-add-breadcrumbs-to-any-page/
?
?
Magento產(chǎn)品頁面的面包屑導(dǎo)航很怪異:如果從Category產(chǎn)品列表中進(jìn)入Product,則面包屑導(dǎo)航中含有Category Path; 否則,當(dāng)從首頁,或搜索結(jié)果中,或者其他什么地方進(jìn)入,則缺少之。我想,可能是Magento支持一個(gè)產(chǎn)品放入多個(gè)Category的緣故吧。不管怎么 樣,產(chǎn)品頁中缺少了Category Path,用戶體驗(yàn)不大好。如下:
?

?
修正的方法,找到文件
app/code/core/Mage/Catalog/Helper/Data.php
?
復(fù)制一份到local代碼池
app/code/local/Mage/Catalog/Helper/Data.php
?
在函數(shù)getBreadcrumbPath的開始部分,加上如下的代碼邏輯:
/** * Return current category path or get it from current category * and creating array of categories|product paths for breadcrumbs * * @return string */ public function getBreadcrumbPath() { // added by p.c.w.l 20110603 if ($this->getProduct() && !$this->getCategory()) { $_categoryIds = $this->getProduct()->getCategoryIds(); if ($_categoryId = $_categoryIds[0]) { $_category = Mage::getModel('catalog/category')->load($_categoryId); Mage::register('current_category', $_category); } } // ...?
首先判斷當(dāng)前是否是產(chǎn)品頁,如果是并且沒有Category信息,就獲取產(chǎn)品所屬的Category IDs, Magento 中一個(gè)產(chǎn)品可以加入多個(gè)Category中,但不管三七二十一只挑出其中一個(gè)幸運(yùn)的Category作為current_category。看最終的效果:

?
?
來源: http://www.sqlstudy.com/article/magento-product-page-breadcrumb-add-category-path.html
?
Magento產(chǎn)品頁面包屑導(dǎo)航(Breadcrumb)修正 Showing Breadcrumbs Anywhere in Magento
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
