【问题标题】:Magento - displaying parent and child categories in a dropdown menuMagento - 在下拉菜单中显示父子类别
【发布时间】:2011-09-15 07:47:56
【问题描述】:

我们目前正在 Magento 中处理我们的类别页面,并使用以下代码为我们所在的类别提供子类别列表。

我们有以下设置:

商店 - 类别 1 - 光泽颜色(父级) -- 子猫 1 - Zurfiz (儿童) -- 子猫 2 - 帕拉潘(儿童)

下拉屏幕截图: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; ?>

【问题讨论】:

  • 我们正在寻找修改代码以显示“显示全部”选项并链接到下拉菜单中的父类别以及子类别,有谁知道我们应该拉出什么代码为此?

标签: php magento categories


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多