当前在类别视图页面中,其子类别以列表格式显示。我想更改列表以选择选项,因此当有太多的子类别时,用户无需一直滚动到底部以查看内容。

当前代码:

<ul>
<?php foreach ($this->getCurrentCategory()->getChildrenCategories() as $_subcat): ?>
    <li><a href="<?php echo $_subcat->getUrl() ?>"><?php echo Mage::helper('catalog/output')->categoryAttribute($_subcat, $_subcat->getName(), 'name') ?></a></li>
<?php endforeach ?>
</ul>
.

如何完成此操作,以便在选择选项中显示子类别?

有帮助吗?

解决方案

只需用...替换该代码...

<?php if($this->getCurrentCategory()->getChildrenCount() > 0) { ?>
    <select onchange="document.location = this.options[this.selectedIndex].getAttribute('rel')">
    <?php foreach ($this->getCurrentCategory()->getChildrenCategories() as $_subcat): ?>
        <option rel="<?php echo $_subcat->getUrl(); ?>"><?php echo Mage::helper('catalog/output')->categoryAttribute($_subcat, $_subcat->getName(), 'name'); ?></option>
    <?php endforeach ?>
    </select>
<?php } ?>
.

这将创建一个下拉的选择完全相同类别的选择框,该组合将与现有代码一起显示,它还将在单击选择时将用户导航到类别。

编辑:现在测试和工作代码。

其他提示

这可能会帮助您。

<select id="category" class="myinput-text required-entry widthinput" name="category">
<?php
  $parentid=5; // parent id which you want sub category
  $categories=explode(',',Mage::getModel('catalog/category')->load($parentid)->getChildren());
  foreach($categories as $cat){
  $category=Mage::getModel('catalog/category')->load($cat);
?>
<option value="<?php echo $category->getId();?>"><?php echo $category->getName();?></option>
<?php } ?>
</select>
.

许可以下: CC-BY-SA归因
scroll top