使Magento 1.9产品过滤器可折叠 [英] Make Magento 1.9 product filter collapsible

查看:52
本文介绍了使Magento 1.9产品过滤器可折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我编辑了以下几行:< dt><?php echo $ this-> __($ _ filter-> getName())?></dt>

< dt>< a href ="/"><?php echo $ this-> __($ _ filter-> getName())吗?</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");返回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-> __('购物选项')?></p>< dl id =按列表缩小"><?php $ _filters = $ this-> getFilters()?><?php foreach($ _ filters作为$ _filters):?><?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");返回false;});});/*]]>*/</script> 

有人知道为什么这行不通吗?

解决方案

您在链接标记上创建了click事件

您可以使用以下href属性来欺骗您的JavaScript:

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

,然后您的jquery click函数将照常触发.

I'm trying to make the product filter for a magento shop collapsible. I tried editing the view.phtml in template/category/layer/view.phtml But it's not working.

I Edited these lines: <dt><?php echo $this->__($_filter->getName()) ?></dt>

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

and i added some jquery like this:

<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> 

Current code:

?>
<?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>

Anyone any idea why this is not working?

解决方案

You made a click event on a link tag

You can trick your javascript with this href attribute:

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

and then your jquery click function will be triggered as usual.

这篇关于使Magento 1.9产品过滤器可折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆