实现首页显示热门关键字,排序并控制显示数量--Show sorted Popular Search Terms

帖子原址:http://www.magentocommerce.com/boards/viewthread/49255/

★把下面的代码,拷贝到记事本,以UTF-8形式另存为 /app/design/frontend/default/f002/template/catalogsearch/term.phtml

ENG:copy the code below into Notepad, Save it as /app/design/frontend/default/f002/template/catalogsearch/term.phtml in UTF-8

 

<?php
/**
 * Magento
 *来自小方,
 *Email: lanshunfang#163.com--Replace # as @

 */
?>
<div class="box base-mini mini-cart">
<
div class="head">
    <
h4><?php echo $this->__('Popular Search Terms'?></h4>
</
div>
<?php if( sizeof($this->getTerms()) > ): ?>

    
<div class="content" id="popSearchTerms">
    <
ul class="bare-list">
        
<?php 
        $i 
0;
        
$getRatioSort $this->getTerms();

        
//小方添加的,对热门关键字数组进行降序排序
        
foreach ($getRatioSort  as $key => $row{
    $volume[$key]  
$row->getRatio();//获取排序用的列标识

}

array_multisort
($volumeSORT_DESC,  $getRatioSort);//根据获取排序用的列标识,进行排序

        
        
foreach ($getRatioSort as $_term)://循环输出排序结果
            
        
if ($i>50)//只循环输出最多50个产品
        
{
        
break;
        
}
        
        
else if ($_term->getRatio() > 0.5)//热度不得低于0.5
        
{
        ?>
            
            
<li><a href="<?php echo $this->getSearchUrl($_term) ?>" style="font-size:<?php echo $_term->getRatio()*70+75 ?>%;"><?php echo $this->htmlEscape($_term->getName()) ?></a></li>
        
<?php 
        $i
++;
        
}
        
        
endforeach; ?>
    
</ul>
    </
div>

<?php else: ?>
    
<div class="note-msg">
        
<?php echo $this->__('There are no search terms available.'); ?>
    
</div>
<?php endif ?>
</div>

 

★在CMS中的首页里面的自定义设计里调用
ENG: Call this in CMS->editing “Home Page"->Custom Design

 

<reference name="right">
<
block type="catalogsearch/term" name="catalogsearch.term" template="catalogsearch/term.phtml" /> 
    </
reference>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值