0

I am working on a theme which is customized by someone else.

So in

/websitename.com/app/design/frontend/rwd/ysv/template/page/category.phtml

is created which is called.When I click on any category or subcategory.

I want to show breadcrumbs, when user is on category/sub-category page.

echo $this->getLayout()->getBlock('breadcrumbs')->toHtml();
This will not help in my case i think.

System > Configuration > General > Web > Default Pages > Show Breadcrumbs for CMS Pages. is set to YES.

Update:

<catalog_category_default translate="label">
        <label>Catalog Category (Non-Anchor)</label>
    .........
     <reference name="content">
            <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
                <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>         <!-- Addedd -->

and

    <catalog_category_layered translate="label">
        <label>Catalog Category (Anchor)</label>
      .....................
        <reference name="content">
            <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
                <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                    <block type="core/text_list" name="product_list.name.after" as="name.after" />
                    <block type="core/text_list" name="product_list.after" as="after" />
                    <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                        <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>     <!-- Addedd -->      

In page.xml

<!-- category (default) -->
    <catalog_category_default>
    <reference name="root">
      <action method="setTemplate"><template>page/category.phtml</template></action>
    </reference>
    </catalog_category_default>

In category.phtml

<?php echo $this->getChildHtml('head'); ?>
<?php echo $this->getChildHtml('after_body_start'); ?>

<!-- global messages -->
<?php echo $this->getChildHtml('global_notices'); ?>

<!-- header -->
<?php echo $this->getChildHtml('header'); ?>

<!-- content -->
<?php echo $this->getChildHtml('content'); ?>

<!-- footer -->
<?php echo $this->getChildHtml('footer'); ?>
<?php echo $this->getChildHtml('before_body_end'); ?>
<?php echo $this->getAbsoluteFooter(); ?>

Can I create dynamic breadcrumbs based on current URL in a custom module or any other method? Please suggest.

2 Answers 2

0

You can add breadcrumbs to your custom page using xml. Add following xml code in your theme's local.xml file.

<module_controller_action translate="label">
   <reference name="breadcrumbs"> 
      <action method="addCrumb"> <!--add breadcrumb-->
         <name>home</name>
           <params> 
             <label>Home</label> 
             <title>Home</title> 
             <link>/</link> 
           </params> 
      </action>
      <action method="addCrumb"> <!--add breadcrumb-->
         <name>custompage</name>
           <params> 
             <label>custompage</label> 
             <title>custompage</title> 
             <link>/custom/page/link</link> 
           </params> 
      </action> 
   </reference>
</module_controller_action>
2
  • how i will decide that on which category i am ,
    – inrsaurabh
    Commented Nov 14, 2017 at 6:36
  • You asked for adding breadcrumbs in your custom module that's why I posted this answer. If you are looking for category, then follow @Piyush's answer Commented Nov 14, 2017 at 6:45
0

For categories Just add below code in your catalog.xml for catalog_category_layered and catalog_category_default layout handle

<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>

For custom pages you can follow @Dinesh's Answer

Update: Along with Dinesh's answer if you want to set name and url dynamically you can use helper method for this. for eg:-

<action method="addCrumb">
    <!-- First breadcrumbs name -->
    <name helper="yourmodule/getName"/>
    <!-- add label, title, link  -->
    <params helper="yourmodule/getHomeUrl" />
</action>

In your helper function

public function getHomeUrl()
{
    return array(
        "label" => $this->__('Home'),
        "title" => $this->__('Home'),
        "link" => custom_url
    );
}


public function getName()
{
    return $name;
}

Add below code in category.phtml after global_notices

<?php echo $this->getChildHtml('breadcrumbs') ?></div>
13
  • i updated my quetion
    – inrsaurabh
    Commented Nov 14, 2017 at 6:47
  • add the given code just after <reference name="content">
    – Piyush
    Commented Nov 14, 2017 at 6:48
  • i am not on frontend/rwd/default/template/page/2columns-right.phtml
    – inrsaurabh
    Commented Nov 14, 2017 at 6:54
  • i am on frontend/rwd/default/template/page/categories.phtml
    – inrsaurabh
    Commented Nov 14, 2017 at 6:55
  • is it your custom page?
    – Piyush
    Commented Nov 14, 2017 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.