2

How to get Custom attribute in listing page

I Have Mobile Category all Mobile Product Under Mobile Attribute Set under that all product only 2 attributes are Filterable Attribute. I am using Custom .pthml for some category with 1colums.phtml

How to Get that 2 filterable attribute in that custom.phtml

Like This way

enter image description here

3
1

Quick check: try changing your XML <name> to <template>:

    <reference name="product_list">
        <action method="setTemplate"><template>catalog/product/list.phtml</template></action>
    </reference>

But:

Layered navigation can be tricky to set up. It has a number of parts to it:

  1. The attribute must be set up for 'Use in Layered navigation' via the Magento Admin pages Catalog->Attributes->Manage Attributes. Ensure the attributes you want have 'Use in Layered navigation' set to 'Filterable (with results)'. Save the attribute.

  2. Likewise, ensure the attributes you don't want have 'Use in Layered navigation' set to 'no'. I note that in default Magento the price attribute is set to 'Filterable (with results)' so you need to change that to 'no'. Save the attribute.

  3. In every category that you want to see this 'layered navigation' you need to set the category 'Is anchor' to 'yes' via Magento Admin pages Catalog->Manage categories->Display settings tab, set 'Is anchor' to 'yes'. Save the category.

After that you may not need to use a custom phtml file to achieve your goal.

Now to the code.

The theme you are using or writing should have a 'local.xml' file in the folder /app/design/frontend/[your theme name]/[default or your theme variation]/layout/local.xml.

If it doesn't have a local.xml you should consider creating this file. You can use it to keep all your layout updates in one place. For example copy the rwd theme's /app/design/frontend/rwd/default/layout/catalog.xml and rename it local.xml and throw away all the XML except the node <catalog_category_layered translate="label"> which you should read, understand and edit to achieve the layout you seek.

With reference to the rwd theme's catalog.xml <catalog_category_layered translate="label">, that XML '<catalog_category_layered>' is what Magento afficionados refer to as the layout update handle for categories that are set 'Is anchor' = 'yes'.

I recommend you put your layout update inside this 'layout update handle' so that it is applied to only categories that you have set to have layered navigation (that is Is Anchor = yes).

So you might get something like this:

<!-- file /app/design/frontend/[your theme name]/[default or your theme variation]/layout/local.xml -->
<layouts>
   <catalog_category_layered>
        <reference name="product_list">
            <action method="setTemplate"><template>catalog/product/list.phtml</template></action>
        </reference>
   </catalog_category_layered>
</layouts>

However, now I am confused about your screen shot and I am confused about the phtml file you are trying to customise, and I am confused about what you are trying to achieve.

It looks like the theme you have is putting some kind of layered navigation in a panel under the 'Design ^' button. Is that right? It is always hard to comment on custom themes but if you study very carefully these three files:

your custom theme's layout update for <catalog_category_layered>, and the rwd one /app/design/frontend/rwd/default/layout/catalog.xml, and the magento base theme /app/design/frontend/base/default/layout/catalog.xml

I hope you can deduce the correct XML to do what you want to do.

I do not think that /catalog/product/custom.phtml nee /catalog/product/list.phtml is the phtml file that is responsible for the 'design panel' in your screenshot. It is much more likely to be one or all of the files

/catalog/layer/view.phtml /catalog/layer/state.phtml /catalog/layer/filter.phtml

If you have only one category in which you want to use a different custom.phtml then you are correct to put the layout update in the Manage Categories->Custom Design->Custom Layout Update text box

<reference name="product_list">
    <action method="setTemplate"><template>catalog/product/list.phtml</template></action>
</reference>

And also remember I suspect /catalog/product/custom.phtml is not the template file you seek to customise.

I think you want to customise /catalog/layer/view.phtml

If this is not the answer please explain in more detail what you are trying to achieve and give some indication of your custom theme's <catalog_category_layered> XML node.

0

If I understood right, what you're trying to achieve is displaying the layered navigation at the top of your product list using a custom template.

To do so you first need to update your layout like this:

<reference name="product_list">
<block type="catalog/layer_view" name="catalog.toplayer" template="catalog/layer/view.phtml"/>
</reference>

Then in your custom template, simply add the following code before the code that displays the products:

<?php echo $this->getChildHtml('catalog.toplayer'); ?>

That should do the trick, even if you will probably need to adapt the design to fit your needs.

Regarding the fact that you have only two attributes that are filterable in your mobile attribute set, only those two should come up in the layered navigation.

4
  • Where i need to add this reference also i need only two attribute not all attributes
    – Magento 2
    Mar 9 '16 at 5:13
  • It will display all category, price & attributes of that category right
    – Magento 2
    Mar 9 '16 at 5:24
  • @LearningMagento the layout needs to be added to your custom layout update XML, the same as you changed the template. See my edit for displaying only the two attributes you need. Mar 9 '16 at 8:12
  • I am not getting. That layer navigation will show price and category also i don't want that in this category also. this code i need to add under Custom design or what
    – Magento 2
    Mar 9 '16 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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