当前位置: 首页 > 开店指南 > ecshop教程 >

如何在首页显示热门点击商品

时间:2010-08-14 14:12来源:banma.cc 作者:banma 点击:
很多客户都在问一些这样的问题,如何在首页显示这个,如何在首页显示那个,这里我们就以如何在首页显示热门点击商品为例来说明下。首先说明下,这篇文章是针对有编程基础的人来说的,不会的...

很多客户都在问一些这样的问题,如何在首页显示这个,如何在首页显示那个,这里我们就以如何在首页显示热门点击商品为例来说明下。

首先说明下,这篇文章是针对有编程基础的人来说的,不会的就可以不用看了

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}-->

 

当然上面的现实方式是随意写的,你喜欢的话可以写出其它格式。



(责任编辑:admin)
BB霜 韩国BB霜 BB霜排行榜 指甲油 灰指甲 灰指甲的治疗方法 灰指甲的症状 灰指甲的治疗偏方