Magento: display a list of subcategories

I am creating a Magento store and want to be able to display a list of categories and have a link to each category on my page.

I have the β€œBrands” category with ID 42, and I want to display a list of subcategories and make sure that each of them refers to the specified URL key in the CMS.

Has anyone had any experience with Magento?

+4
source share
7 answers

If you are comfortable editing the topic, this code snippet will provide you with a list of all the subcategories of the current category (from the session, so this should work anywhere in your topic). I usually use this in app / design / frontend / default / theme_name / template / catalog / category / view.phtml

<?php $_category = $this->getCurrentCategory(); $collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id); $helper = Mage::helper('catalog/category'); ?> <ul> <?php foreach ($collection as $cat):?> <?php if($_category->getIsActive()):?> <?php $cur_category = Mage::getModel('catalog/category')->load($cat->getId()); $_img = $cur_category->getImageUrl(); ?> <li> <a href="<?php echo $helper->getCategoryUrl($cat);?>"> <img src="<?php echo $_img?>" title="<?php echo $cat->getName();?>"/> <cite><?php echo $cat->getName();?></cite> </a> </li> <?php endif?> <?php endforeach;?> </ul> 
+17
source

If you want to display top level categories and subcategories that U can perform like this ...

 <?php $_helper = Mage::helper('catalog/category') ?> <?php $_categories = $_helper->getStoreCategories() ?> <?php $currentCategory = Mage::registry('current_category') ?> <?php if (count($_categories) > 0): ?> <ul> <?php foreach($_categories as $_category): ?> <li> <a href="<?php echo $_helper->getCategoryUrl($_category) ?>"> <?php echo $_category->getName() ?> </a> <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?> <?php $_subcategories = $_category->getChildrenCategories() ?> <?php if (count($_subcategories) > 0): ?> <ul> <?php foreach($_subcategories as $_subcategory): ?> <li> <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"> <?php echo $_subcategory->getName() ?> </a> </li> <?php endforeach; ?> </ul> <?php endif; ?> </li> <?php endforeach; ?> </ul> <?php endif; ?> 

When displaying top-level categories and current SubCategories, you can do as ....

 <?php $_helper = Mage::helper('catalog/category') ?> <?php $_categories = $_helper->getStoreCategories() ?> <?php $currentCategory = Mage::registry('current_category') ?> <?php if (count($_categories) > 0): ?> <ul> <?php foreach($_categories as $_category): ?> <li> <a href="<?php echo $_helper->getCategoryUrl($_category) ?>"> <?php echo $_category->getName() ?> </a> <?php if ($currentCategory && $currentCategory->getId() == $_category->getId()): ?> <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?> <?php $_subcategories = $_category->getChildrenCategories() ?> <?php if (count($_subcategories) > 0): ?> <ul> <?php foreach($_subcategories as $_subcategory): ?> <li> <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"> <?php echo $_subcategory->getName() ?> </a> </li> <?php endforeach; ?> </ul> <?php endif; ?> <?php endif; ?> </li> <?php endforeach; ?> </ul> <?php endif; ?> 
+4
source

This question requires a long answer. I will show you the right places.

1) The best solution is to use a free extension. I have not tried it, but it will do the trick. You will need to do some CSS to get the right look.

http://www.magentocommerce.com/extension/1562/magento-easy-catalog-images Demo: http://extension01.templates-master.com/gb/electronics.html

2) I do not believe in modules, as it can become difficult to upgrade if the supplier decided to stop supporting it. I used the information from the following forum topic to create vew sites. Look ... It can't be straightforward. You may need to make several copies of the main files in a local directory.

http://www.magentocommerce.com/boards/viewthread/3770/P30/

Hope this helps you :)

+2
source

I made this little video on how I create blocks with personal category lists with Magento. I am sure that there are better ways to achieve this or even something that I could do better, but this is only my method. I just created this in the hope that it will help explain some things there.

Magento Custom Listing Block

Thanks!

+1
source

having looked at all the solutions on the magento website, I found that the wookiehangover solution above works and took about 8 seconds.

creates a UL that you can create. Thank you

+1
source

After creating the static block, you can get any list of subcategories with this script:

  $_helper = Mage::helper('catalog/category'); $_category = Mage::getModel('catalog/category')->load(5); $_subcategories = $_category->getChildrenCategories(); if (count($_subcategories) <= 0) { return; } $count = 0; foreach($_subcategories as $_category) { $category = Mage::getModel('catalog/category')->load($_category->getId()); $ret->{"object_".$count} ->url = $_helper->getCategoryUrl($_category); $ret->{"object_".$count} ->name = $_category->getName(); $ret->{"object_".$count} ->id = $_category->getId(); $ret->{"object_".$count} ->image = $category->getImageUrl(); $count++; } return $ret; } $list = list_subcategories(5); echo "<pre>"; print_r($list); echo "</pre>"; ?> 
+1
source

How to list only categories belonging to the current item. Not all categories on the page.

But in the form of a tree, as a species.

CATEGORY - swap 1 CATEGORIE 2 - sub cat 1 - sub sub cat 1

BR Cveto

-one
source

All Articles