Magento Web Developer

How to List Sub Categories Products on Category Page in Magento?

Rushik Shah User Icon By: Rushik Shah

Magento is ecommerce software and is available to download freely from their website. It is highly robust software, which is one of the reasons that it has risen to popularity so fast. Magneto by itself has many features built into it and thus reduces the need for you to add any extensions. However there are many extensions available for you to install into Magento to enhance the user experience. Furthermore if you wish for a truly unique website or custom functionality it is likely you will need the assistance of a Magento Web developer.

The steps below describe how to list sub-categories on a category page:-

1. For this you need to go to the admin section of the Magento installation.

2. From the admin menu you need to select CMS Static Blocks

3. Hit the ‘Add New Block’ button on the top right.

Create a new block by the name ‘Subcategory Listing’ with the following content:

{{block type=”catalog/navigation” template=”catalog/navigation/subcategory_listing.phtml” }}

Now save the block and go back to the admin menu.
Select Catalog > Manage Categories from the admin menu
Select the category that has sub-categories and under the ‘Display Settings Tab’ reflect the following:

Display mode: Static Block only
Only CMS Block: Sub Category Listing
Is Anchor: No

Save this by hitting ‘Save Category’ on the top right.
We now need to create a new file by the name ‘subcategory_listing.phtml’ with the following content.

Screenshot

Screenshot

Now connect to your web server directory using FTP and browser to where your Magento files are stored.
Go to the directory app/design/frontend/default//template/catalog/navigation/ and upload this file created above. You can create the directories missing from the path above if required.

While on the FTP connection is still alive you need to go to the directory app/code/core/Mage/Catalog/Block/Navigation.php and download the file navigation.php.

Now still on the FTP, navigate to the directory app/code/local/Mage/Catalog/Block and upload the copied navigation.php file to this directory.

Now open the file navigation.php in your favourite editor and look for the following code:

public function getCurrentChildCategories()

{
$layer = Mage::getSingleton(‘catalog/layer’);
$category = $layer->getCurrentCategory();
/* @var $category Mage_Catalog_Model_Category */
$categories = $category->getChildrenCategories();
$product Collection = Mage::getResourceModel(‘catalog/product_collection’);
$layer->prepared Product Collection($product Collection);
$product Collection->add Count To Categories($categories);
return $categories;
}

Replace this code with the following:

public function getCurrentChildCategories()
{
$layer = Mage::getSingleton(‘catalog/layer’);
$category = $layer->getCurrentCategory();
/* @var $category Mage_Catalog_Model_Category */
$collection = Mage::getModel(‘catalog/category’)->getCollection();
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
$collection->addAttributeToSelect(‘url_key’)
->addAttributeToSelect(‘name’)
->addAttributeToSelect(‘is_anchor’)
->addAttributeToSelect(‘image’)
->addAttributeToFilter(‘is_active’, 1)
->addEd Filter($category->getChildren())
->setOrder(‘position’, ‘ASC’)
->join UrlRewrite()
->load();

$product Collection = Mage::getResourceModel(‘catalog/product_collection’);
$layer->prepared Product Collection($product Collection);
$product Collection->add Count To Categories($collection);
return $collection;
}

Now re-upload this file to the web server.

That is it you are done; if you browse to the frontend of the site and open the category with the sub-categories added to it should show the subcategories listed.

If in case they are not present you may need to clear the Magento cache first and then attempt load the page.

Feel free to contact our Magento web development team today.

Why Choose Alakmalak As a Your Growth Partner?

Looking to outsource Website Design & Development Work?

Alakmalak is a web development company in India that offers services for several technologies. There have been around for a very long time and have developed over 2500 projects for clients all around the world. They have highly skilled web developers with a great deal of experience.

  • how to list sub categories poducts on category page in magento?

What’s Next ?

I know after reading such an interesting article you will be waiting for more. Here are the best opportunities waiting for you.

Share via
Copy link
Powered by Social Snap