1

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.

4
  • is three is root cat id?
    – Amit Bera
    Sep 2, 2014 at 9:41
  • Root cat id = 2
    – Francis
    Sep 2, 2014 at 10:09
  • ok.....................
    – Amit Bera
    Sep 2, 2014 at 10:10
  • Ha sorry, I meant to say root cat id is = 3 not 2 lol. My bad.
    – Francis
    Sep 2, 2014 at 10:23

1 Answer 1

0

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

1
  • Thank you very much! Just used that then echo $category->getName(); Oh also your 'catalog/category_collection' is missing its trailing '
    – Francis
    Sep 2, 2014 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.