I am trying to create a custom drop-down-menu with only few specific categories and their respective subcategories. So far I managed to retrieve the Names of the subcategories but links won’t work.
I also need to make the main category retrieve its own name and URL automaticly in case it is changed on the back-end of Magento. In this case the category id is 265.
The website I am working on is http://www.personalproducts4u.co.uk
<li class="eight"><a href="<?php echo $this->getUrl() ?>index.php/contacts">Hotel Products</a>
<?php $children = Mage::getModel('catalog/category')->getCategories(265); ?>
<ul>
<?php foreach ($children as $category): ?>
<li>
<a href="<?php echo $category->getUrl ?>">
<?php echo $category->getName(); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</li>
The problem is that the
$childrencollection is of typeVarien_Data_Tree_Node_Collectionand its elements respectively are of typeVarien_Data_Tree_Node. CallinggetUrl()on them will return null, they are notMage_Catalog_Model_Categoryobjects. However, you can retrieve their request path (url) by calling:Alternatively you can load the category object by calling:
And then use the
$cat->getUrl()call. This loading will add an extra overhead though.