Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3434830
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:44:47+00:00 2026-05-18T07:44:47+00:00

In Magento, I’ve created a phtml template file with the code below. I got

  • 0

In Magento, I’ve created a phtml template file with the code below. I got this from this tutorial. Me and others are wondering how to sort this category list alphabetically. The first lines of code create an array with Category IDs. Further down, we can get the Category Name using the ID within the foreach section. But to sort by Name, we need to get the Names in an array before the foreach and then sort 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 id of the parent category for which I want to list subcategories. Also, I’m not putting this is a category page template. I’m inserting as a block in a CMS page (that part is already working).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:44:48+00:00Added an answer on May 18, 2026 at 7:44 am

    You could build a list of category names first.

    <?php
    $cats = Mage::getModel('catalog/category')->load(319)->getChildren();
    $catIds = explode(',',$cats);
    
    $categories = array();
    foreach($catIds as $catId) {
           $category = Mage::getModel('catalog/category')->load($catId); 
           $categories[$category->getName()] = $category->getUrl();
    }
    
    ksort($categories, SORT_STRING);
    ?>
    
    <ul>
    <?php foreach($categories as $name => $url): ?>
        <li>
        <a href="<?php echo $url; ?>"><?php echo $name; ?></a>
        </li>
    <?php endforeach; ?>
    </ul>
    

    I wrote this answer without knowing too much about Magento and just wanting something quickly that worked. Anton’s answer is better and more Magentic(?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Magento shopping cart is built on the Zend Framework in PHP. This is the
In Magento you can override a block (or helper, or model, etc.) from one
I have Magento 1.3.2 and I have weird issue: When I am in list.phtml
Magento is a newish (past 5 years) PHP based Ecommerce system with an architecture
Magento provide translation feature, a nice one for e-commerce platform. But it seems to
Magento 1.4 Default Product Details image size is 265x265. All of our product images
Magento Production version 1.2.1 store running on linux centos. I want to hide all
In magento, I have SEO url rewriting enabled, and it is working fine -
In Magento I'm creating a custom module and would love to be able to
HI Magento introduced a new concept of widget in magento 1.4 , my question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.