0

只是给你一个想法。我有 3 个级别的类别。
顶级 > 子类别 > 子类别的子类别

我不想显示的是子类别的孩子。

下面的代码显示了每个类别。(抱歉,粘贴的格式不太好。)

<?php
// ----   PRODUCT NAVIGATION ---- \\
$nav_obj = new Mage_Catalog_Block_Navigation();
$store_cats = $nav_obj->getStoreCategories();
$current_cat = $nav_obj->getCurrentCategory();
?>

<ul>

<?php foreach ($store_cats as $cat):?>
<?php
$ids = strtolower(str_replace(" ", "_", $cat->getName()));
$ids = str_replace("&", "", $ids);
?>


<li class="parent" id="<?php echo $ids; ?>"><?php echo $cat->getName()?>

<ul>
<?php foreach (Mage::getModel('catalog/category')->load($cat->getId())->getChildrenCategories() as $childCategory): ?>
<li><a href="<?php echo $childCategory->getUrl(); ?>">
<?php echo $childCategory->getName()?></a></li>
<?php endforeach; ?>
</ul>
</li>

<?php endforeach; ?>
4

1 回答 1

0

我正在做类似的事情。我基本上是通过每个类别并渲染我想要渲染的东西:

<?php # get category list ?>
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>

<?php foreach($_categories as $_category) : ?>
    <?php # turn it into the proper model object ?>
    <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
    <a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a>         
    <?php foreach($_category->getChildrenCategories() as $_subCategory) : ?>
         <a href="<?php echo $_subCategory->getUrl() ?>"><?php echo $_subCategory->getName() ?></a>
    <?php endforeach ?>
<?php endforeach ?>
于 2012-05-08T19:30:52.667 回答