In the home page of my Magento store I have created a featured category section where I have placed a button with drop down where I would like to list any specific categories name and link as a drop down list with the help of category id (Get only the category name and link to it those IDs are specified, not the sub-categories of it). How do I accomplish it in a .phtml file? Very new to magento so every help will be a lot for me.
1 Answer
To Display Top Level Category only Try the Below code...
<?php $_helper = Mage::helper('catalog/category') ?> // create a object of helper class.
<?php $_categories = $_helper->getStoreCategories() ?> // fetch you store category
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
You have
<?php $_helper = Mage::helper('catalog/category') ?> // create a object of helper class.
Just put the code in your .phtml file and make CSS as per you need.
-
Thanks, I don't want to get all the store categories but specific categories that are under Default Category >> Inventory. I think I have to use something like
Mage::getModel('catalog/category')->getCategories(4);
– Kevin SCommented Sep 26, 2014 at 13:46 -
1no if you have category Id then
$data=Mage::getModel('catalog/category')->load(4)
Simple and printprint_r($data->getData())
Commented Sep 26, 2014 at 14:46