Magento Web Developer

How to Create Sub Categories On Magento?

Rushik Shah User Icon By: Rushik Shah

These steps below explain how to list sub-categories on a category page:

1. First of all you need to go to the admin section of the Magento ecommerce website.

2. Go to the admin menu and select CMS > Static Blocks

How to Create Sub Categories On Magento?

Magento Admin Menu
3. Now on the page that loads, click on the ‘Add New Block’ button on the top right.

4. You now need to create a new block called ‘Sub Category Listing’ with the following content:

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

Add New Block

Add New Block
1. Go back the admin menu once you have saved this.

2. Select Catalog > Manage Categories from the admin menu

3. Go to the ‘Display Settings Tab’ and select the category which has sub-categories to reflect the following:

>Display mode: Static Block only

>Only CMS Block: Sub Category Listing

>Is Anchor: No

4. Save this by clicking on the ‘Save Category’ on the top right section of the page.

5. Once that is done, create a new file by the name ‘subcategory_listing.phtml’ with the following content.

  • Now use FTP to connect to your web server and then 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.

 

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

 

  • You the need to 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();
$productCollection = Mage::getResourceModel(‘catalog/product_collection’);
$layer->prepareProductCollection($productCollection);
$productCollection->addCountToCategories($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)
->addIdFilter($category->getChildren())
->setOrder(‘position’, ‘ASC’)
->joinUrlRewrite()
->load();

$productCollection = Mage::getResourceModel(‘catalog/product_collection’);
$layer->prepareProductCollection($productCollection);
$productCollection->addCountToCategories($collection);
return $collection;
}

  • Now upload this file to the web server using the same FTP connection.

 

  • 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 sub-categories 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 developer 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 Create Sub Categories On 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