Magento – Get specific categories Name and URL to it

category

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.

Best 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.

Related Topic