2011-05-23 73 views
0

我想在列表页面上显示当前类别的子类别(如果有),但是如果没有子类别,并且当前类别不是主类别,则显示相同的级别类别。如何按级别显示类别?

<?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. 

     //} 

    ?> 
+0

我在目录/分类/ view.phtml – kharonayee 2011-05-23 06:21:26

+0

这听起来客户非常混乱这样做。我建议整个反对它。 – 2011-05-23 11:45:33

回答

1

您需要首先获取当前类别的父类别标识。然后使用父类别ID加载产品(就像您在脚本中所做的那样)。

为了实现下列后应该会有所帮助

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

+0

tnx队友:)它帮助了很多:) – kharonayee 2011-05-23 07:05:58

+0

不客气的兄弟...有一个愉快的一天:) – 2011-05-23 07:29:05