0
我有一段代码,用于查找是否存在某个类别的子类别,如果存在,则它会在列表视图中显示子类别。仅当子类别大于1时才显示Div
我想添加一个函数,说如果子类超过1,然后显示一个DIV,如果没有,那么不要显示DIV,因为它不会显示任何子类别。
这是我迄今为止,但它似乎并没有工作。
<?php
/* Load category by id */
$cat = Mage::registry('current_category');
/*Returns comma separated ids*/
$subcats = $cat->getChildren();
if (count($subcats) > 0): ?>
<div style="width:100%; height:auto; text-align:center; font-size:16px; color:#373737; padding:2px 0; margin-top:-5px; margin-bottom:3px; background:#f1f1f1;">Choose Your Category</div>
<?php endif;
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());
}
}
?>
工作就像一个魅力:) – Matt