2

I have a website in magento. i want show all categories whether it is active or not.

I have tried but it doesnt show inactive categories.

Can any give a suggestion to solve this problem ?

Thanks.

4 Answers 4

3

try this one... this will surely help you...

$categories = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToSelect('*')//or you can just add some attributes
    ->addAttributeToFilter('level', 2)//2 is actually the first level;

add this filter option if you want all active categories.

$categories = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToSelect('*')//or you can just add some attributes
    ->addAttributeToFilter('level', 2)//2 is actually the first level
  ->addAttributeToFilter('is_active', 1);//if you want only active categories
3

Please refer this link, may be help you,

http://fishpig.co.uk/magento/tutorials/display-categories-and-subcategories-in-magento/

Regards.

0
2

Here is the correct code:

    <?php 

$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addLevelFilter(2);

$b_path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
?> 
<div class="nav-container">
<ul id="nav">
<?php
foreach($categories as $cat)
{
$category = Mage::getModel('catalog/category')->load($cat->getentity_id()); 
if($category ->getname() == 'Root Catalog' || $category ->getname() == 'Default Category' )
{}else{
?>



<li><a href="<?php echo $b_path.$category ->geturl_path() ?>"><?php echo $category ->getname(); ?></a></li>
<?php }} ?>
</ul>
</div>

Thanks

0
2
<?php
/*
 * http://fishpig.co.uk - Magento Tutorials
 *
 * Display top level categories and subcategories
 *
**/
?>
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_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>
                <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                <?php $_subcategories = $_category->getChildrenCategories() ?>
                <?php if (count($_subcategories) > 0): ?>
                    <ul>
                        <?php foreach($_subcategories as $_subcategory): ?>
                            <li>
                                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                    <?php echo $_subcategory->getName() ?>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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