0

我想在 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> 

该脚本是否应该运行良好,并且构建良好?先感谢您!

4

1 回答 1

1

您可能想在模板级别使用 jQuery 'drawer' 来控制它。

您可以在此处查看有关如何创建的更多信息:http: //jqueryfordesigners.com/slide-out-and-drawer-effect/

于 2013-01-02T16:04:55.093 回答