Magento – How to alphabetically sort categories

magento-1.9

I have a page that is setup to display all product categories. How do I sort these alphabetically?

This is what the block looks like

{{block type="core/template" template="catalog/category/cat-thumbnails.phtml"}} {{block type="core/template" template="catalog/category/sidebar-fix.phtml"}}

I just want to alphabetize it.

Best Answer

For that you need to create on block file in your custom module,for example here I create one block file and in that file, you set custom category collection.

class Namespace_Module_Model_Getcategory extends Mage_Core_Model_Abstract
{
    public function getCategory($page,$limit)
    {
        $categories = Mage::getModel('catalog/category')
        ->getCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('is_active', array('in' => array(1)))
        ->addAttributeToFilter('parent_id', array('neq' => array(1)))
        ->addIsActiveFilter()
        ->addAttributeToSort('name','ASC');


    return $categories;

}

}

now call phtml with this block name like,

{{block type="module/blockname" template="catalog/category/cat-thumbnails.phtml"}}

and get the custom collection in your phtml.

Related Topic