How to get the url of the [Magento] category in this code?

0

This code returns me the categories of the Magento but I could not make it increment the url of the category so that it is clickable and go to the page of the corresponding category. Can you help me?

    <ul>
        <?php
            $obj = new Mage_Catalog_Block_Navigation();
            $storeCategories = $obj->getStoreCategories();
            Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
            foreach ($storeCategories as $_category):
        ?>

        <li>
            <strong>
                <?php echo "<a href=".$_category->getUrl().">" . $_category->getName(); "</a>"; ?>
            </strong>
        </li>
       <?php endforeach; ?>
    </ul>
    
asked by anonymous 22.01.2015 / 13:29

1 answer

1

The $obj->getStoreCategories() takes basic information from the category that does not include the url, ideally then it is to have the direct reference or a new object, I prefer the direct reference as the code below:

<ul>
    <?php
        $obj = new Mage_Catalog_Block_Navigation();
        $storeCategories = $obj->getStoreCategories();
        Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
        foreach ($storeCategories as $_category):
            $url = Mage::getModel('catalog/category')->load($_category->getId())->getUrl();
            // altere a variavel no echo  abaixou ou defina o valor
            // $_category->setUrl($url);
    ?>    
    <li>
        <strong>
            <?php echo "<a href=".$_category->getUrl().">" . $_category->getName(); "</a>"; ?>
        </strong>
    </li>
   <?php endforeach; ?>
</ul>
    
20.02.2015 / 15:34