0

Can anyone advise how to list categories in a CMS page? For example, we have a category for each brand in our shop. I would like to list them all in a single CMS page. I realise I could do this using HTML but I want it to be automated, so if I disable a category it is removed from the list on the CMS page.

I wonder if there's an extension that achieves this or whether it can be done using something built into Magento?

Thank you.

2
  • you want just the top level categories or all of them as a tree structure?
    – Marius
    Commented Mar 7, 2016 at 9:40
  • They are all located under the category 'brands' - and it would just be the top level categories under the brands category. Commented Mar 7, 2016 at 21:36

2 Answers 2

1

The cms pages do not allow php code. You can create a template to display your content and you can include it in CMS page like this:

{{block type="core/template" template="path/to/template.phtml"}}

And put below mentioned code in this file:

<?php 
        $parentCategoryId = 31;
        $category = Mage::getModel('catalog/category')->load($parentCategoryId );
        $children = Mage::getModel('catalog/category')->getCollection()->setStoreId(Mage::app()->getStore()->getId());
        $children->addAttributeToSelect('*')->addAttributeToFilter('parent_id', $category->getId())
        ->addAttributeToFilter('is_active', 1)//get only active categories if you want
        ->addAttributeToSort('name');//sort by position 
     ?>
    <div class="brands">
                     <ul>
             <?php foreach ($children as $child){ 

                     $skin_url = $child->getImageUrl(); ?>          
                    <li><a href="<?php echo $child->getURL();?>" title="<?php echo $child->getName();?>"><img src="<?php echo $skin_url?>" />               

                    <span class="brand-name"><?php echo $child->getName();?></span>
                    </a>
                    </li>

            <?php   }?>                     
            </ul>
    </div>

Ho it will help you.

3
  • Adding that code to a CMS page doesn't give the expected result. Can PHP script be used directly in a CMS page? Commented Mar 7, 2016 at 21:38
  • The cms pages do not allow php code. You can create a template to display your content and you can include it in the page like this: {{block type="core/template" template="path/to/template.phtml"}}
    – Arunendra
    Commented Mar 8, 2016 at 4:33
  • Thank you. Just a note for anyone else that the parent category ID in the script above needs to be changed to the relevant ID in your own store. In my instance this was a change of '31' to '5'. Commented Mar 8, 2016 at 9:53
0

AFAIK There is no build-in function for what you are asking.

You should create a CMS widget iterating your categories.

Here there is a nice tutorial on how to create widgets: http://code.tutsplus.com/tutorials/custom-widget-development-in-magento--cms-23015

To get a list of your store categories you could use:

$categories = Mage::getModel('catalog/category')
  ->getCollection()
  ->addAttributeToSelect('*')
  ->addIsActiveFilter()
  ->addLevelFilter(1);

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.