ecshop首页显示热门点击商品

本文详细介绍了如何在ecshop首页自定义展示热门点击商品的功能,包括编写调用函数和整合到页面显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 ecshop在首页没有提共热门点击商品的展示,如果要展示就需要自己写调用函数了。

首先在index.php里最后加一个函数,

大概如下:

function getMostClickGoods($cat,$sum){
    $sql = " select * from ". $GLOBALS['ecs']->table('goods') ." where is_delete=0 and (" . get_children($cats) . " OR " . get_extension_goods($cats) .") order by click_count";
 $res = $GLOBALS['db']->selectLimit($sql, $sum,0);

    $idx = 0;
    $goods = array();
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
 $goods[$idx]['id']           = $row['goods_id'];
        $goods[$idx]['name']         = $row['goods_name'];
        $goods[$idx]['catname']         = $row['cat_name'];
        $goods[$idx]['caturl']         =  build_uri('category', array('cid'=> $row['cat_id']));
        $goods[$idx]['brief']        = $row['goods_brief'];
        $goods[$idx]['brand_name']   = $row['brand_name'];
        $goods[$idx]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
                                       sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        $goods[$idx]['market_price'] = price_format($row['market_price']);
        $goods[$idx]['shop_price']   = price_format($row['shop_price']);
 }
   return $goods;
  }

接下来就是调用了,

 $smarty->assign('most_click_goods',        getMostClickGoods(22,8));

然后就是在index.dwt里,这时就像循环其它数组变量一样,使用smarty标签循环这个变量即可。

<!-- {foreach  from=$most_click_goods item=goods}-->
       <div class="clickgoodslist"> 
   <a href="/{$goods.url}"   title="{$goods.name|escape:html}"><img src="/{$goods.goods_img}" alt="{$goods.name|escape:html}"/></a>
</div>
<!--{/foreach}-->

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值