php 面包屑

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 面包屑相关的知识,希望对你有一定的参考价值。


<?php echo $this->getLayout()->getBlock("breadcrumbs")->toHtml(); ?> 

\!h ----- move in list.phtml

What I did was
put this code inside the handler

<catalog_category_default>
<reference name="root">
<action method="unsetChild"><name>breadcrumbs</name></action>
</reference>
<catalog_category_default>

which removes the display of breadcrumb from the top of the pages.

Now I could use this piece of code

<?php echo $this->getLayout()->getBlock('breadcrumbs')->toHtml(); ?>

------------------------------------------------

<?php echo $this->getChildHtml('breadcrumbsContainer') ?>

<block type="core/text_list" name="breadcrumbs.container" as="breadcrumbsContainer" translate="label">
                <label>Breadcrumbs</label>
                <block type="page/html_breadcrumbs" name="breadcrumbs"/>
            </block>


\!h ----- breadcrumbs anywhere

Добавление Breadcrumbs на страницы где их нет по умолчанию

Можно добавить или в файле phtml:

<?php
$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('get_in_touch', array('label'=>'Get in touch', 'title'=>'Get in touch'));         
echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();
?>

Или добавить в XML файл

<reference name="breadcrumbs">
    <action method="addCrumb">
        <crumbName>Home</crumbName>
        <crumbInfo><label>Home</label><title>Home</title><link>/</link></crumbInfo>
    </action>
    <action method="addCrumb">
        <crumbName>My Account</crumbName>
        <crumbInfo><label>My Account</label><title>My Account</title><link>/customer/account</link></crumbInfo>
    </action>
    <action method="addCrumb">
        <crumbName>Login</crumbName>
        <crumbInfo><label>Login</label><title>Login</title></crumbInfo>
    </action>
</reference>


You are right, there is no hierarchy of CMS pages in Magento. The best solution would be to create a real hierarchy by adding a parent_id to CMS pages and modifying the CMS module to handle nested URLs and breadcrumbs. But that requires a lot of coding.

A quick-and-dirty hack is to modify the breadcrumbs manually on each subpage by adding something like this to the layout update XML:

<reference name="root">
<action method="unsetChild"><alias>breadcrumbs</alias></action>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
    <action method="addCrumb">
        <crumbName>home</crumbName>
        <crumbInfo><label>Home page</label><title>Home page</title><link>/</link></crumbInfo>
    </action>
    <action method="addCrumb">
        <crumbName>myparentpage</crumbName>
        <crumbInfo><label>My Parent Page</label><title>My Parent Page</title><link>/myparentpage/</link></crumbInfo>
    </action>
    <action method="addCrumb">
        <crumbName>mysubpage</crumbName>
        <crumbInfo><label>My Sub Page</label><title>My Sub Page</title></crumbInfo>
    </action>
</block>
</reference>

以上是关于php 面包屑的主要内容,如果未能解决你的问题,请参考以下文章

php WooCommerce面包屑

php 面包屑

php 面包屑

php 面包屑

php WordPress SEO面包屑

php 创世纪面包屑。