Happy new year everyone, hope this year brings you and your loved ones all the happiness, health and prosperity. We thought we should contribute one article in the beginning of the new year to help our Magento community.
As we all know Magento has a lot of great features and one of the features Magento has is layered navigation filters. These filters are quite flexible, scalable and dynamic but there is only one small problem with them that they are not Google or search engine friendly. The reason for that these filters create duplicate links for all the category pages on the website which means it ends up creating duplicate content on the website. And as you now Google doesn’t like duplicate content so we created a module (http://www.scommerce-mage.co.uk/magento-extensions/google-friendly-layered-navigation.html) which resolves this problem and is going to be soon available on Magento connect for you to download and provide some feedback.
But today we are going to talk about how can we override phtml or layout core files in Magento without changing default theme.
Create a new module under your local folder, in our case under /app/local/Scommerce/LayeredNavigation. Now create config.xml in etc folder with the following -:
<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Scommerce_LayeredNavigation> <version>0.0.1</version> </Scommerce_LayeredNavigation> </modules> <frontend> <layout> <updates> <scommerce_layered> <file>scommerce_layered.xml</file> </scommerce_layered> </updates> </layout> </frontend> </config>
N.B. – You can give any name in the file but we would suggest that create unique name because if you create any common name then it might conflicts with Magento future releases. That’s why in our case we chose a safe option by calling our layout file scommerce_layered.xml
Create scommerce_layered.xml under app/design/frontend/base/default/layout
<?xml version="1.0"?> <layout version="0.1.0"> <catalog_category_layered translate="label"> <reference name="catalog.leftnav"> <action method="setTemplate"> <template>scommerce/layer/view.phtml</template> </action> </reference> </catalog_category_layered> </layout>
In the above step, we are instructing that Magento should use our view.phtml instead of Magento’s view.phtml for layered navigation which generally is at the following path app/design/frontend/base/default/template/catalog/layer/
This is the most important step of all!
Create your module file in /etc/modules/Scommerce_LayeredNavigation.xml
<Scommerce_LayeredNavigation> <active>true</active> <codePool>local</codePool> </Scommerce_LayeredNavigation>
That’s it, it is as simple as that. Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.