Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Magento中显示更多/更少属性_Php_Magento - Fatal编程技术网

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

Php 在Magento中显示更多/更少属性,php,magento,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;

我想在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> 
转到app/design/frontend/default/YOUR_THEME/template/catalog/layer/filter.phtml
将现有代码替换为:
现在打开同一文件夹中的文件view.phtml
在开头添加:
如果($\u filter->getItemsCount())出现以下情况,请在前面添加:
如果($\u过滤器->GetItemScont()>$displaySize)
$hiddenFilters[]=strtolower($_filter->getName());
在文件末尾添加:
事件。观察(窗口“加载”,
函数(){

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

您可以在此处查看有关如何创建的更多信息:

我们一定会看一看的!谢谢!