Showing featured categories in homepage is one of the requirement on my ongoing magento project (ongoing at the time i’m posting this blog). The one way i could use to achieve this is via adding custom category field in magento categories. And while fetching category collection using that custom field filter. This is how it looks like featching categories with filter of custom field value

Note : i suppose is_featured is the name of added custom field of type yes/no.

But i’m not going through this way. i’m going through module technique that would allow you to just multiselect categories from system configuration. This way looks nice to me as i don’t need to create custom field on magento default, and go though all categories to select if is featured or not. This would allow admin to select/unselect categories from a single place.

For this i’m going to need these file for our module

  • Sumankcdotcom_Customconfig.xml – to enable our module (app/code/etc/modules/)
  • config.xml – our module configuration file (app/code/local/Sumankcdotcom/Customconfig/etc/)
  • system.xml – xml file to write configuration option for our module (app/code/local/Sumankcdotcom/Customconfig/etc/)
  • Options.php – a model file to populate options for our custom field (app/code/local/Sumankcdotcom/Customconfig/Model/)
  • Data.php – helper file just to make sure, magento translation works properly, it’s more a convention (app/code/local/Sumankcdotcom/Customconfig/Helper/Data.php)

Step 1: For this first i’m going to register a module. (If you have some existing custom module you can use that).

File location : app/code/etc/modules/Sumankcdotcom_Customconfig.xml

Step 2: Writing our module configuration file config.xml

This declares the model and helper classes as per the magento class declaration convention. and the <adminhtml> tag is used to define resource for the admin.

Step 3: Create our backend config via system.xml file with following content

In this file we created backend configuration. We created a multiselect field where we will populate categories.

Step 4: Populating categories in previously created multiselect field. And this is what we do via our model file Options.php

And finally the remaining file from the list above Data.php, an empty file just to make sure magento translation system works properly.

Till now we completed creating backend configuration and populating categories inside multiselect in custom option which looks like this


Now as we select/unselect categories name from this multiselect configuration, we could get those selected values in phtml file via getStoreConfig. (in our case this line gives the selected categories array Mage::getStoreConfig(‘customconfig_options/featured_categories/select_cat’))

Step 5 : Frontend

we are going to create a phtml file which would fetch those selected categories. (app/design/frontend/<Your_package>/<Your_theme>/template/catalog/category/featured-categories.phtml)

In this file above we are fetched system config and now we are populating categories image, url and name in ul list.

Now as we have created this core/template file, we are going to embed in homepage via xml. In backend > cms > pages> homepage : Design section > Layout Update XML update with

Or you can embed on other layout handles via your local.xml file.

Suman K.C

eCommerce Developer, writes about stuff related to eCommerce development. Currently based in Kathamandu, loves reading about startups & new technology, introvert nature, fond of traveling & playing volleyball.

More Posts - Website

Follow Me:
LinkedInGoogle Plus