【问题标题】:Magento: Create Block Displaying Multiple Categories and SubcategoriesMagento:创建显示多个类别和子类别的块
【发布时间】:2013-07-13 20:17:32
【问题描述】:

作为这个问题的序言,我是一名前端开发人员,对 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 类 第 2 类 第三类

但我想要的是这个

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

等等……

谁能帮我解决这个问题?

非常感谢!

【问题讨论】:

    标签: php magento e-commerce magento-1.7


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      • 2015-02-14
      • 2011-07-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多