Php Magento显示主类别和一级子类别的正确方式
只是给你一个想法。我有三个级别的类别。Php Magento显示主类别和一级子类别的正确方式,php,magento,Php,Magento,只是给你一个想法。我有三个级别的类别。 顶级>子类别>子类别的子类别 我不想显示子类别的子类别 下面的代码显示了每个类别。(很抱歉,粘贴的格式不太好。) 我正在做一件类似的事情。我基本上是在传递每个类别,并呈现我想要呈现的内容: <?php # get category list ?> <?php $_helper = Mage::helper('catalog/category') ?> <?php $_categories = $_helper->ge
顶级>子类别>子类别的子类别 我不想显示子类别的子类别 下面的代码显示了每个类别。(很抱歉,粘贴的格式不太好。)
我正在做一件类似的事情。我基本上是在传递每个类别,并呈现我想要呈现的内容:
<?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 ?>
<?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 ?>