1

我正在使用 Magento 并在 ID 下有一个类别99。我想使用 HTML 无序列表显示它及其子项。如何?

4

2 回答 2

1

I copied and reformatted this code from the original question. Credits to Clint Hubbard Jr.

<ul>
  <li>
    <h2>
      <a href="<?php echo Mage::getModel("catalog/category")->load(99)->getUrl() ?>">
        <?php echo Mage::getModel("catalog/category")->load(99)->getName() ?>
      </a>
    </h2>
  </li>
  <?php $children = Mage::getModel('catalog/category')->getCategories(118) ?>
  <?php foreach ($children as $category): ?> 
    <li>
      <a href="<?php echo $category->getUrl(); ?>">
        <?php echo $category->getName(); ?>
      </a>
    </li>
  <?php endforeach; ?>
</ul>

Request the category model with Mage::getModel() then load instance with ID 99 and retrieve its URL and its name. Then get its children in an array and go into a foreach loop (with the PHP alternate control structure with the colon and endforeach).

于 2012-10-13T11:53:13.730 回答
0

显然我的类别模型请求不够具体,下面是解决方案并解决了获取正确 url 的问题。

<ul class="menu-list-1">
  <li>
    <h2>
      <a href="<?php echo Mage::getModel("catalog/category")->load(99)->getUrl() ?>">
        <?php echo Mage::getModel("catalog/category")->load(99)->getName() ?>
      </a>
    </h2>
  </li>
  <?php foreach (Mage::getModel('catalog/category')->load(99)->getChildrenCategories() as $childCategory): ?>
    <li>
      <a href="<?php echo $childCategory->getUrl(); ?>">
        <?php echo $childCategory->getName(); ?>
      </a>
    </li>
  <?php endforeach; ?>
</ul>
于 2012-10-15T18:18:59.390 回答