1

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.

2

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 S Sep 26 '14 at 13:46
  • 1
    no if you have category Id then $data=Mage::getModel('catalog/category')->load(4) Simple and print print_r($data->getData()) – Keyul Shah Sep 26 '14 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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