In Magento, I created a phtml template file with the code below. I got this from this tutorial . I and others are interested in how to sort this list of categories in alphabetical order. The first lines of code create an array with category identifiers. Next, we can get the category name using the identifier in the foreach section. But to sort by name, we need to get the names in the array before foreach, and then sort them by name. How?
<?php
$cats = Mage::getModel('catalog/category')->load(319)->getChildren();
$catIds = explode(',',$cats);
?>
<ul>
<?php foreach($catIds as $catId): ?>
<li>
<?php
$category = Mage::getModel('catalog/category')->load($catId);
echo '<a href="' . $category->getUrl() . '">';
echo $category->getName() . '</a>';
?>
</li>
<?php endforeach; ?>
</ul>
Note. 319 is the category identifier of the parent category for which I want to list subcategories. In addition, I did not put this category page template. I insert as a block on the CMS page (this part is already working).