在Magento中显示更多/更少的属性

时间:2013-01-02 15:35:28

标签: php magento

我想在Magento属性中创建一个显示更少/更多按钮。目前,导航中有50种不同颜色或类似物的块。是否可以减少节目/显示更多按钮?我在互联网上找到的唯一一件事是:

Go to the app/design/frontend/default/YOUR_THEME/template/catalog/layer/filter.phtml 

Replace the existing code with: 

<ol> 
 <?php 
 $displaySize=4; 
 $i=0; 
 $filterName=strtolower($this->getName()); 
 $cnt=count($this->getItems()); 
 foreach ($this->getItems() as $_item): ?> 
 <?php if($i == $displaySize) { ?> 
 <div id="more-<?php echo $filterName?>"><a >Show Filter</a></div> 
 <div id="cont-<?php echo $filterName?>"> 
 <?php } ?> 
 <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 echo $_item->getCount() ?>) 
 </li> 
 <?php $i++; 
 if($i==$cnt && $cnt > $displaySize) 
 echo '<div id="less-'.$filterName.'"><a >Hide Filter</a></div></div>'; ?> 
 <?php endforeach ?> 
 </ol> 
 Now open the file view.phtml in the same folder 

 Add in the beginning: 

<?php $displaySize=4; 
 $hiddenFilters=array(); ?> 
 Add just before if($_filter->getItemsCount()): 

if($_filter->getItemsCount() > $displaySize) 
 $hiddenFilters[]=strtolower($_filter->getName()); 
 Add at the end of file: 

<script> 
 Event.observe(window, ‘load’, 
function() { 
 <?php foreach($hiddenFilters as $v) 
 { 
 echo "$('cont-".$v."').hide();"; 
 } ?> 
 } 
 ); 

 // Register event ‘click’ and associated call back. 
 Event.observe(document, ‘click’, respondToClick); 

 // Callback function to handle the event. 
 function respondToClick(event) { 
 var element = event.element(); 
 //------ 
 <?php foreach($hiddenFilters as $p) 
 { 
 echo "if(element.up('div').id=='more-".$p."') 
 { 
 $('cont-".$p."').show(); 
 $('more-".$p."').hide(); 
 } 
 if(element.up('div').id=='less-".$p."') 
 { 
 $('cont-".$p."').hide(); 
 $('more-".$p."').show(); 
 }"; 
 } ?> 

 //----- 

 } 

 </script> 

这个脚本应该运行良好,并且构建良好吗? 提前谢谢!

1 个答案:

答案 0 :(得分:1)

您可能希望在模板级别使用jQuery“抽屉”来控制它。

您可以在此处详细了解如何创建一个: http://jqueryfordesigners.com/slide-out-and-drawer-effect/