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

Asked

Viewed 266 times

0

This code returns me the categories of Magento but I could not make it increment the category url to be 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>

1 answer

1


The $obj->getStoreCategories() takes basic category information that does not include the url, the ideal then is to have direct reference or a new object, I prefer direct reference as 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.