Get a Free Quote

We respect your privacy

How to list Sub-categories Products on a Category Page in Magento?

5:58 am

How to list Sub-categories Products on a Category Page in Magento?

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 from 2013-11-06 11:20:21

Screenshot from 2013-11-06 11:21:13

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.

If you like this blog Please Plus it, Like It ,Tweet It and best yet link to It.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...Loading...

Comments are closed.