Magento:创建显示多个类别和子类别的块


Magento: Create Block Displaying Multiple Categories and Subcategories

在回答这个问题之前,我是一名前端开发人员,对php的了解有限。我试图在Magento的左侧导航中显示所有类别和子类别。我使用在GitHub上找到的方法创建了一个phtml文件。这很好地拉入顶级类别,但我也想显示子类别。这是我现在的代码:

<?php $_categories=$this->getCurrentChildCategories() ?>
<?php if($_categories->count()): ?>
<ul class="category-links"> 
<?php foreach ($_categories as $_category): ?>
    <?php if($_category->getIsActive()): ?>
    <li class="<?php echo $this->htmlEscape($_category->getUrlKey()) ?>">
       <a href="<?php echo $this->getCategoryUrl($_category) ?>">
          <?php echo $this->htmlEscape($_category->getName()) ?>
       </a>
    </li>
    <?php endif; ?>
    <?php endforeach ?>
</ul>
<? endif; ?>

这包括以下类别:

类别1类别23类

但我想要的是这个

类别1类别1的子类别1类别1的子类别2类别2类别2的子类别1第2类第2子类

等等…

有人能帮我吗?

非常感谢!

类似的内容。你需要检查一下,因为我没有尝试过,但也许它会让你走上正轨。

<?php $_categories=$this->getCurrentChildCategories() ?>
<?php if($_categories->count()): ?>
<ul class="category-links"> 
<?php foreach ($_categories as $_category): ?>
    <?php if($_category->getIsActive()): ?>
    <li class="<?php echo $this->htmlEscape($_category->getUrlKey()) ?>">
       <a href="<?php echo $this->getCategoryUrl($_category) ?>">
          <?php echo $this->htmlEscape($_category->getName()) ?>
       </a>
    </li>
    <?php $_subcategories = $_category->getChildrenCategories();
    foreach ($_subcategories as $_subcategory):?>
    <li class="<?php echo $this->htmlEscape($_subcategory->getUrlKey()) ?>">
       <a href="<?php echo $this->getCategoryUrl($_subcategory) ?>">
          <?php echo $this->htmlEscape($_subcategory->getName()) ?>
       </a>
    </li>
    <?php endforeach; ?>
    <?php endif; ?>
    <?php endforeach ?>
</ul>
<? endif; ?>