Question

Now I feel stupid asking this, I had this answer 3 days ago, changed a part of my code and now have completely forgotten how to pull the main category name which should be easy enough.

I have

<div class="footer-links-container">
<?php $categoryId =3; ?>
<div class="footer-block-title">
    <?php echo "<h3>Scotch Whisky</h3>" ;?>
</div>
<?php $children = Mage::getModel('catalog/category')->load($categoryId)->getChildrenCategories(); ?>
<div class="custom-footer-content">
<ul>
    <?php foreach ($children as $subCategory){
            echo '<li><a href="' . $subCategory->getUrl() . '">' . $subCategory->getName() . '</a></li>';
        }
    ?>
</ul>
<div class="clear">&nbsp;</div>
</div>
</div>

What is it I do again to pull the actual category name? I tried echo $categoryId->getName(); but that seemed to throw me an error.

Was it helpful?

Solution

just used

 $category=Mage::getModel('catalog/category')->load($categoryId);
$children = Mage::getResourceModel('catalog/category_collection)->addAttributeToSelect('url_key')
            ->addAttributeToSelect('name')
            ->addAttributeToSelect('all_children')
            ->addAttributeToSelect('is_anchor')
            ->addAttributeToFilter('is_active', 1)
            ->addIdFilter($category->getChildren())
            ->setOrder('position', Varien_Db_Select::SQL_ASC)
            ->joinUrlRewrite()
            ->load();

Instead of

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

If it not work then you need to reindexing from Index management at admin

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top