我们目前正在使用Magento中的类别页面,并提供以下代码,以提供我们所在类别的子类别列表。
我们有以下设置:
商店 - 猫1 - 光泽颜色(父母) - Sub cat 1 - Zurfiz(儿童) - Sub cat 2 - Parapan(儿童)
下拉菜单截图:http://awesomescreenshot.com/048kga35a
我们希望修改代码以显示“全部显示”选项并链接到下拉菜单中的父类别以及子类别,是否有人知道我们应该为此提取哪些代码?
来自app \ design \ frontend \ default [我们的模板] \ template \ catalog \ navigation \ left.phtml
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories=$this->getCurrentChildCategories() ?>
<?php
$oLayer = null;
$oCat = $this->getCurrentCategory();
# level 3 categories display their category siblings
if (3 === (int)$oCat->getData('level')) {
# get the layer object
$oLayer = Mage::getSingleton('catalog/layer');
$oParentCategory = $oCat->getParentCategory();
# set the parent category as the current category
$oLayer->setData('current_category',$oParentCategory);
# load the child categories
$_categories = $this->getCurrentChildCategories();
}
?>
<?php if($_categories->count()): ?>
<div class="box layered-nav">
<?php
# switch back the current category
if (null !== $oLayer) $oLayer->setData('current_category',$oCat);
?>
<script language="javascript" type="text/javascript" >
function jumpto(x){
if (document.form1.jumpmenu.value != "null") {
document.location.href = x
}
}
</script>
<div class="cat-dropdown">
<form name="catlist">
<select name="jumpmenu" onChange="jumpto(document.catlist.jumpmenu.options[document.catlist.jumpmenu.options.selectedIndex].value)">
<option value="#">Choose a brand</option>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<option value="<?php echo $this->getCategoryUrl($_category) ?>"><?php echo $this->htmlEscape($_category->getName()) ?> (<?php echo $_category->getProductCount() ?>)</option>
<?php endif; ?>
<?php endforeach ?>
</select>
</form>
</div>
</div>
<?php endif; ?>
答案 0 :(得分:1)
使用此代码..
<?php
//$id = whatever
$subcats = Mage::getModel('catalog/category')->load($id)->getAllChildren();
?>
<select name="jumpmenu">
<option value="#">Choose a brand</option>
<?php
foreach(explode(',',$subcats) as $subCatid)
{
$_category = Mage::getModel('catalog/category')->load($subCatid);
//print_r($_category);
?>
<option value="<?php echo $_category->getCategoryUrl() ?>"><?php echo htmlEscape($_category->getName()) ?></option>
<?php } ?>
</select>