0

This pulls a list of all our category thumbnails and the name. I want to sort it alphabetically.-

<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
    ->addAttributeToSelect(array('name', 'thumbnail'))
    ->addAttributeToFilter('is_active', 1)
    ->addIdFilter($category->getChildren())
?>

<ul class="subcatthumbnails" id="cat-thumb-box">
<?php foreach ($categories as $category): ?>
    <li>
        <a href="<?php echo $category->getUrl() ?>"><img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
            <span><?php echo $category->getName() ?></span></a>
    </li>
<?php endforeach; ?>
</ul>

I am trying to figure out how to sort it alphabetically.

2 Answers 2

0

Try

    <?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
    ->addAttributeToSelect(array('name', 'thumbnail'))
    ->addAttributeToFilter('is_active', 1)
    ->addIdFilter($category->getChildren())
    ->addOrderField('name')
?>
-1

Add this code

->setOrder('name', 'ASC')

after

->addIdFilter($category->getChildren())

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.