Search code examples
phpparsingmagentoe-commercegeturl

Magento getUrl not working with catalog/category object?


I've been able to instantiate a category object to retrieve its name, but when I use the getUrl method it isn't returning a URL to the category listing page, or anything at all

<?php
$children = Mage::getModel('catalog/category')->getCategories(3);
foreach ($children as $category):
            echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>';
        endforeach;
?> 

The code above results in HTML output of

<li><a href="">name of sub-cat</a></li>`

Does anyone know how I can get the URL for a category page from a catalog/category object?


Solution

  • Replace

    $children = Mage::getModel('catalog/category')->getCategories(3);
    

    with

    $children = Mage::getModel('catalog/category')->load(3)->getChildrenCategories();