Magento How to display/list all categories from catalog category flat table

magentomagento-1.7

I have enabled "Use Flat Catalog Category" & "Use Flat Catalog Product" to "yes" for getting better performance. But after enabling this options one of my previous cms page on which I was getting a list of all subcategories is not working anymore.
The code using which I was getting sub-categories before enabling flat data is:

$_category = Mage::getModel('catalog/category')->load(CATEGORY-ID);    
$_categories = $_category->getCollection()->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
                ->addAttributeToFilter('is_active', 1)
                ->addIdFilter($_category->getChildren())
                ->setOrder('position', 'ASC')
                ->joinUrlRewrite();

Note: I have checked that, both of my flat data tables have been successfully populated. This code still works if I change the "Use Flat Catalog Category" option to "No".
Now, what should be the code to get a list of category along with its subcategories where as it may pull data from "catalog_category_flat_store_*" table?

Best Answer

Here I got this code working

    $_category = Mage::getModel('catalog/category')->load(CATEGORY-ID);    
    $_categories = $_category
                    ->getCollection()
                    ->addAttributeToSelect(array('name', 'image', 'description'))
                    ->addIdFilter($_category->getChildren());

    foreach ($_categories as $_category):
       echo $_category->getName();
    endforeach;
Related Topic