1. 下拉框 Select Box
You have plain text and link to those text in Magento Layered Navigation section. You can easily change the display of Layered Navigation links into a selection box / dropdown list. To do so, you need to edit the following file:

app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/catalog/layer/filter.phtml

filter.phtml file contains code something like below:

<ol>
<?php foreach ($this->getItems() as $_item): ?><li>      <?php if ($_item->getCount() > 0): ?><a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a><?php else: echo $_item->getLabel() ?><?php endif; ?><?php if ($this->shouldDisplayProductCount()): ?>(<?php echo $_item->getCount() ?>)<?php endif; ?></li>
<?php endforeach ?>
</ol>

Here is the edit to filter.phtml that will display selection box / dropdown list in layered navigation. You just need to replace the code of your filter.phtml file with the code shown below:

<select name="layered-nav-select" onChange="setLocation(this.value)"><option selected="selected" value="#">Please Select</option><?php foreach ($this->getItems() as $_item): ?>                <?php if ($_item->getCount() > 0): ?><option value="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?phpecho $_item->getLabel();if ($this->shouldDisplayProductCount()):echo '(' . $_item->getCount() . ')';endif; ?></option>             <?php else: ?><option value="#"><?phpecho $_item->getLabel();if ($this->shouldDisplayProductCount()):echo '(' . $_item->getCount() . ')';endif; ?></option><?php endif; ?>        <?php endforeach ?>
</select>

Now, you should be able to view selection list in your layered navigation section in frontend.

2. 按钮 Button

<?php foreach ($this->getItems() as $_item): ?>
<?php $_label      = str_replace(array('"',"'",' '), array('','','-'), strtolower($_item->getLabel())) ?>
<?php $_url        = $this->urlEscape($_item->getUrl()) ?>
<?php $_remove_url = $this->urlEscape($_item->getRemoveUrl()) ?>
<?php $_get_attr   = $_item->getFilter()->getRequestVar() ?>
<?php //echo 'tester:<pre>'; print_r($_item->getFilter()->getResetValue()); echo '</pre>';?> <button type="button" class="btn btn-default btn-size filter-button<?php echo $_item->getMSelected() ? ' active-button' : '' ?>" data-url="<?php echo $_remove_url ?>" data-remove-url="<?php echo $_url ?>"><?php echo $_item->getLabel() ?></button>
<?php endforeach ?>

3. 复选框 checkbox

<?php foreach ($this->getItems() as $_item): ?>
<?php $_label      = str_replace(array('"',"'",' '), array('','','-'), strtolower($_item->getLabel())) ?>
<?php $_url        = $this->urlEscape($_item->getUrl()) ?>
<?php $_remove_url = $this->urlEscape($_item->getRemoveUrl()) ?>
<?php $_get_attr   = $_item->getFilter()->getRequestVar() ?>
<?php //echo 'tester:<pre>'; print_r($_item->getFilter()->getResetValue()); echo '</pre>';?> <div class="checkbox"> <input type="checkbox" <?php echo $_item->getMSelected() ? 'checked="checked"' : '' ?> class="filter-button<?php echo $_item->getMSelected() ? ' active-button' : '' ?>" data-url="<?php echo $_url ?>" data-remove-url="<?php echo $_remove_url ?>" data-count="<?php echo $_item->getCount() ?>" value="" /> <label><?php echo $_item->getLabel() ?></label></div><?php endforeach ?>

4. 色彩框 color

<?php foreach ($this->getItems() as $_item): ?>
<?php $_label      = str_replace(array('"',"'",' '), array('','','-'), strtolower($_item->getLabel())) ?>
<?php $_url        = $this->urlEscape($_item->getUrl()) ?>
<?php $_remove_url = $this->urlEscape($_item->getRemoveUrl()) ?>
<?php $_get_attr   = $_item->getFilter()->getRequestVar() ?>
<?php //echo 'tester:<pre>'; print_r($_item->getFilter()->getResetValue()); echo '</pre>';?> <span class="btn btn-default filter-button btn-color btn-circle-micro<?php echo $_item->getMSelected() ? ' active-button' : '' ?>"data-url="<?php echo $_url ?>" data-remove-url="<?php echo $_remove_url ?>" style="background-color:<?php echo $_label ?>;<?php if(!in_array($_label, array('white','#fff','#ffffff'))) echo 'border:none;'?><?php if(isset($_GET[$_get_attr]) AND $_GET[$_get_attr]) echo $_item->getMSelected() ? '' : 'display:none;' ?>"></span>   <?php endforeach ?>

转自:Magento: 左栏筛选条件 Select Box / Button / Dropdown List on Layered Navigation

Magento: 左栏筛选条件 Select Box / Button / Dropdown List on Layered Navigation相关推荐

  1. magento左栏添加筛选Filtering options on Left-Navigation Menu in Products List Page

    To make sidebar appear on a desired category and contain a desired attribute, you must follow next 3 ...

  2. WPF DevExpress grid 设置自定义筛选栏的条件为包含关系

    WPF DevExpress grid 设置自定义筛选栏的条件为包含关系 根据 DevExpress.Xpf.Grid改造 来源:CSDN  原文:https://blog.csdn.net/alis ...

  3. 【MyBatis使用】mapper.xml 文件内<if test>标签判断参数值不等于null和空 当参数值为 0 时筛选条件失效原因分析(源码探究)

    这个问题有不少小伙伴遇到过,也给出了解决方案,但是没有探究原因,这次读一下源码,看看原因在哪里. 1. 条件失效情况复现 Mapper.xml内的动态SQL如下[伪代码] <select id= ...

  4. vue 自定义 移动端筛选条件

    1.创建组件 components/FilterBar/FilterBar.vue <template><div class="filterbar" :style ...

  5. excel根据条件列转行_Excel vba-根据不同筛选条件筛选后,拆分成新的excel工作簿...

    以下代码为工作中的真实案例(不是真实数据~~~),本人是销售方,每季度都要和关联方进行对账,这工作量大的可怕估计有五六十家关联方,我又不能把所有数据都发送给关联方,最好是根据每个关联方的名字来进行筛选 ...

  6. SQL-聚合函数结果作为筛选条件时where与having用法的区别

    牛客网题目:表user_profile,查看每个学校用户的平均发贴和回帖情况,寻找低活跃度学校进行重点运营,请取出平均发贴数低于5的学校或平均回帖数小于20的学校. 如果用where,则需要用到子查询 ...

  7. Django 实现搜索结果分页(筛选结果分页),以及优雅添加多个筛选条件

    本人另外有一篇文档是专门更新Django的一些操作笔记,有需要可以收藏关注一下:Django笔记 目录 具体实现如下: 效果展示 分页器参考:Django高级之-分页器 场景:在对查询列表进行搜索.排 ...

  8. MySql 别犯糊涂了! LEFT JOIN 的 ON 后接上筛选条件,多个条件会出事!

    很多时候我们在使用  LEFT JOIN   ...... ON .... 时, 除了连接两个表的字段条件外,我们往往还需要一些等值或者范围 等等类似的数据筛选条件. 那么对于初学者,往往会犯一个错误 ...

  9. metaBase的字段筛选条件报错问题总结(多字段下拉选择/metaBase中in语句的用法)

    这几天公司在选型报表,我负责metaBase的研究,发现metaBase的多字段下拉选择时候总是报错,如下sql: select * from org_outp_register register w ...

最新文章

  1. C面向对象之透明指针的运用
  2. blktrace 工具集使用 及其实现原理
  3. 设计模式----模板方法模式UML和实现代码
  4. [转]安装和使用JD-Eclipse插件
  5. android getevent参数,android getevent、sendevent、input keyevent 使用说明
  6. VTK:PolyData之Reflection
  7. 阶段1 语言基础+高级_1-3-Java语言高级_02-继承与多态_第1节 继承_6_继承中方法的覆盖重写_概念...
  8. 《炉石传说》架构设计赏析(2):Scene管理
  9. 【Python7】csv/excel/matplotlib,排序/树遍历,线/进程,文件/xml操作,百度人脸API,aiohttp/hal/restful/curl
  10. array_combine()
  11. 【linux】设置镜像源
  12. 【NOIP2017】宝藏
  13. Matlab-杆单元整体刚度矩阵组装(有限元基础-曾攀)
  14. GPS定位的优点和缺点与室内定位
  15. Java_多线程_模拟电影院售票
  16. walking与Matlab入门教程-控制walking机器人移动
  17. 后退一步 小程序_微信小程序:如何利用navigateBack退出小程序
  18. 2021最新《python爬虫从0-1》5.正则表达式讲解
  19. PCB中走线与电流的关系
  20. JAVA-Gson-格式化输出json字符串

热门文章

  1. Milking Time(POJ-3616)
  2. 动态规划 —— 背包问题 P02 —— 完全背包
  3. 20 WM配置-策略-定义出库排序序列(拣配)
  4. 可以进行单元测试么_为什么程序员都讨厌写单元测试?有一个词叫“相爱相杀”!...
  5. MFC对话框动态刷新图片(仿照全屏屏保)
  6. 为什么通常在类的init函数下一行写super().__init__()?==>就是执行父类的构造函数,使得我们能够调用父类的属性
  7. scala中class与object区别.
  8. web2py的“hello world”
  9. ioca0中断 pic单片机_单片机入门知识-PIC为例程序.ppt
  10. python编程一球从100米_Python基础练习实例20(弹球问题)