开发者

how to display categories by level?

i want to display sub-categories (if any) of a current category on listing page, but if there is no sub-category and also the current category 开发者_运维技巧is not the main category, then display the same level categories.

<?php
        //print_r($_category); exit;

        $Curr_cat_id = $_category->getEntityId();

        $children = Mage::getModel('catalog/category')->getCategories($Curr_cat_id);

        if($children){

            foreach($children as $sub_cat)
            {
               $subCat = Mage::getModel('catalog/category')->load($sub_cat->getId());

               ?>

                <a href="<?php echo $this->getUrl().$sub_cat->getRequestPath(); ?>" >
                    <?php echo $sub_cat->getName(); ?>
                </a><br />

             <?php

            } // end of foreach

        } // end of if

        //else{

          // this is where i want the same level categories if in case there are no sub-categories and also the current category is not a main category.

        //}

    ?>


You need to get the parent category id of your current category first. And then load the products ( like you are doing in your script ) with the parent category id instead.

To achieve that the following post should be of help

http://www.magentocommerce.com/boards/viewthread/16357/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜