我正在使用以下代码来显示您拥有的当前类别的子类别。
但是,我有 2 个级别的子猫,所以我需要能够以某种方式修改代码以仅显示您拥有的当前类别的第 1 级子类别,而不是两个级别?
<?php
/* Load category by id */
$cat = Mage::registry('current_category');
/*Returns comma separated ids*/
$subcats = $cat->getChildren();
foreach(explode(',',$subcats) as $subCatid)
{
$_category = Mage::getModel('catalog/category')->load($subCatid);
if($_category->getIsActive()) {
echo '<li><a href="'.$_category->getURL().'" title="View the products for the "'.$_category->getName().'" category">'.$_category->getName().'</a></li>';
/* Load category by id */
$sub_cat = Mage::getModel('catalog/category')->load($_category->getId());
/*Returns comma separated ids*/
$sub_subcats = $sub_cat->getChildren();
foreach(explode(',',$sub_subcats) as $sub_subCatid)
{
$_sub_category = Mage::getModel('catalog/category')->load($sub_subCatid);
if($_sub_category->getIsActive()) {
echo '<li class="sub_cat"><a href="'.$_sub_category->getURL().'" title="View the products for the "'.$_sub_category->getName().'" category">'.$_sub_category->getName().'</a></li>';
}
}
}
}
?> `