2013-01-02 53 views
0

我想在Magento屬性中顯示更少/更多按鈕。目前,導航中有50個不同顏色的區塊。是否可以減少顯示/顯示更多按鈕?我在網上發現的唯一的東西是這樣的:在Magento中顯示更多/更少屬性

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> 

這個腳本應該運行良好嗎? 提前謝謝!

回答