Question

I tried creating a side bar in magento, using the following code:

<?php $_helper1 = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper1->getStoreCategories(false, true, false); ?>
        <div class="sidebar">
            <h3>Product Categories</h3>
            <ul>
        <?php foreach($_categories as $_category): ?>
    <li>
    <a href="<?php echo $_helper->getCategoryUrl($_category); ?>">
        <p><?php echo $_category->getName(); ?></p>
    </a>
    </li>
  <?php endforeach; ?>              
            </ul>
        </div>

I have already set my categories as the subcategories to default category, and I have cleared my cache and done the fixes stated here:

http://www.aschroder.com/2009/03/top-3-solutions-when-your-magento-categories-are-not-displaying/

I have also set it the Is Anchor option to Yes.

But it still is not showing anything. What is probably wrong with it?

Was it helpful?

Solution

can i suggest another solution?

The best way to get categories is using collections:

<?php $_categories = Mage::getModel('catalog/category')->getCollection()
                     ->addAttributeToSelect('name')
                     ->addAttributeToSelect('is_active'); ?>
    <div class="sidebar">
        <h3>Product Categories</h3>
        <ul>
        <?php foreach($_categories as $_category): ?>
            <li>

                <a href="<?php echo $_category->getUrl();?>">
                    <p><?php echo $_category->getName(); ?></p>
                </a>
           </li>
        <?php endforeach; ?>              
        </ul>
    </div>

Maybe this can help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top