I am working on a site where I am displaying a list of all the subcategories associated with the current category. The code below works fine for that, but I'd like to change the way the list of subcategories is sorted. Currently, it sorts by category ID. I'd like it to show up in whatever order the Magento user put the categories in in the admin (where they can drag-and-drop to change the category order). Appreciate any help!
<?php
$currentCat = Mage::registry('current_category');
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
// current category is a toplevel category
$loadCategory = $currentCat;
}
else
{
// current category is a sub-(or subsub-, etc...)category of a toplevel category
// load the parent category of the current category
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
}
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a>';
}
}
?>