0

我正在使用 Hellowired 主题,顶部导航链接显示在侧栏中。相反,我希望在侧边栏中显示特定类别(ID 3)的子类别。请记住,当用户通过链接导航时,活动非活动状态应该起作用。

这是 leftnav.phtml 中的代码:

 <div class="block block-leftnav">
 <div class="block-title"><strong><span><?php echo $this->__('Shop Categories') ?></span></strong></div>
 <div class="block-content">
 <ul id="leftnav">
 <!-- HOME BUTTON HACK -->

 <?php $_anyActive = false; foreach ($this->getStoreCategories(3) as $_category) { $_anyActive = $_anyActive || $this->isCategoryActive($_category); } ?>
 <li class="home <?php echo !$_anyActive ? 'active' : '' ?>"><a href="<?php echo $this->getUrl('')?>"><span><?php echo $this->__('Home') ?></span></a></li>
 <!-- HOME BUTTON HACK -->
 <?php foreach ($this->getStoreCategories(3) as $_category): ?>
 <?php echo $this->drawItem($_category) ?>
 <?php endforeach ?>
 </ul>
 </div> 
 </div>

帮助表示赞赏。先感谢您。

4

1 回答 1

2

load(3) 中的“3”是类别 ID。

$cat = Mage::getModel('catalog/category')->load(3);
    $subcats = $cat->getChildren();

    foreach(explode(',',$subcats) as $subCatid)
    {
      $_category = Mage::getModel('catalog/category')->load($subCatid);
      if($_category->getIsActive()) {
        $sub_cat = Mage::getModel('catalog/category')->load($_category->getId());
        $sub_subcats = $sub_cat->getChildren();
        foreach(explode(',',$sub_subcats) as $sub_subCatid)
        {
              $_sub_category = Mage::getModel('catalog/category')->load($sub_subCatid);
              if($_sub_category->getIsActive()) {
                  echo '<li class="sub_cat"><a href="'.$_sub_category->getURL().'" title="View products for "'.$_sub_category->getName().'" category">'.$_sub_category->getName().'</a></li>';
              }
         }
      }
    }
于 2013-03-19T12:54:10.123 回答