开发者

how to display categories by level?

开发者 https://www.devze.com 2023-03-07 13:10 出处:网络
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

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

精彩评论

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

关注公众号