使Magento 1.9产品过滤器可折叠


Make Magento 1.9 product filter collapsible

我正在尝试使一个magento商店的产品过滤器可折叠。我试着在template/category/layer/view.phtml中编辑view.phtml,但它不起作用。

我编辑了这些行:<dt><?php echo $this->__($_filter->getName()) ?></dt>

<dt><a href="/"><?php echo $this->__($_filter->getName()) ?></a></dt>

我添加了一些类似的jquery:

<script type="text/javascript">
    /* <![CDATA[ */
    jQuery(document).ready(function(){
        jQuery("dl#narrow-by-list> dd:not(:first)").hide();
        jQuery("dl#narrow-by-list> dt a").click(function(){
            jQuery("dl#narrow-by-list> dd:visible").slideUp("fast");
            jQuery(this).parent().next().slideDown("fast");
            return false;
        });
    });
    /* ]]> */
</script> 

当前代码:

?>
<?php  if($this->canShowBlock()): ?>
<div class="block block-layered-nav">
    <div class="block-title">
        <strong><span><?php  echo $this->__('Shop By')  ?></span></strong>
    </div>
    <div class="block-content">
        <?php  echo $this->getStateHtml()  ?>
        <?php  if ($this->getLayer()->getState()->getFilters()): ?>
            <div class="actions"><a href="<?php  echo $this->getClearUrl()  ?>"><?php  echo $this->__('Clear All')  ?></a></div>
        <?php  endif; ?>
        <?php  if($this->canShowOptions()): ?>
            <p class="block-subtitle"><?php  echo $this->__('Shopping Options')  ?></p>
            <dl id="narrow-by-list">
                <?php  $_filters = $this->getFilters()  ?>
                <?php  foreach ($_filters as $_filter): ?>
                <?php  if($_filter->getItemsCount()): ?>
                    <div class="<?php  if(strcasecmp($_filter->getName(), 'PRICE') == 0) echo 'layered-price'; else echo 'layered-attribute'; ?>">
                        <div class="title-layered"><dt><a href="/"><?php  echo $this->__($_filter->getName())  ?></a></dt></div>
                        <dd><?php  echo $_filter->getHtml()  ?></dd>
                    </div>
                <?php  endif; ?>
                <?php  endforeach; ?>
            </dl>
            <script type="text/javascript">decorateDataList('narrow-by-list')</script>
        <?php  endif; ?>
    </div>
</div>
<?php  endif; ?>
<script type="text/javascript">
    /* <![CDATA[ */
    jQuery(document).ready(function(){
        jQuery("#narrow-by-list> dd:not(:first)").hide();
        jQuery("#narrow-by-list> dt a").click(function(){
            jQuery("#narrow-by-list> dd:visible").slideUp("fast");
            jQuery(this).parent().next().slideDown("fast");
            return false;
        });
    });
    /* ]]> */
</script>

有人知道为什么不起作用吗?

您在链接标签上进行了点击事件

你可以用这个href属性欺骗你的javascript:

<dt><a href="javascript:void(0)"> <?php echo $this->__($_filter->getName()) ?></a></dt>

然后您的jquery点击功能将像往常一样被触发。