Frage

I am in need of some assistance. I am using Magento 1.8.1 and I need to display subcategories in the navigation menu in descending order of their product count.

I have no idea on how to approach the subject, so any hint or possible solution would be greatly appreciated.

Thank you

War es hilfreich?

Lösung

Try below code once. Change your category ID.

<?php
    $cats = Mage::getModel('catalog/category')->load(3)->getChildrenCategories();
?>
 <ul>   
    <?php
    $resourcearray = array();
    foreach($cats as $category): 
    $proCnt = $category->getProductCount();
    $proName = $category->getName();
    $proUrl = $category->getUrl();
    array_push($resourcearray, array('count' => $proCnt, 'name' => $proName,'url' => $proUrl));
    ?>
    <?php endforeach; 
    ksort($resourcearray);
    ?>
    <?php foreach($resourcearray as $val): ?>
        <li>
            <a href="<?php echo $val['url'] ?>"><?php echo $val['name'] ?>(<?php echo $val['count'] ?>)</a>
        </li>
    <?php endforeach;?>
    </ul>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top