长沙做网站在做项目时,客户要求能让销售量前10的排在首页,这样吸引更多的用户。Ecshop是一个强大的开源系统,很多功能需要二次开发就可以实现的。当然这个需求一样可以实现,方法如下:
代码如下:
function get_latest_top10(){ $sql="SELECT DISTINCT a.goods_id,b.goods_name,b.goods_number,b.`goods_thumb`,ROUND(b.`shop_price`,0) AS price FROM (SELECT goods_id,COUNT(DISTINCT rec_id) AS total FROM ecs_order_goods GROUP BY goods_id) a,ecs_goods b WHERE a.`goods_id`=b.`goods_id` ORDER BY a.total DESC LIMIT 10"; return $GLOBALS['db']->getAll($sql); }
这个方法,就能获取到排行榜的商品信息;加在 includes/lib_goods.php 的尾部
如果是首页要调用,就类似这样
$smarty->assign('top_goods', get_latest_top10());
写在 index.php 里
模板里这么调用:
<!-- {foreach name=top_goods from=$top_goods item=goods}--> <ul class="clearfix"> <img src="../images/top_{$smarty.foreach.top_goods.iteration}.gif" class="iteration" /> <!-- {if $smarty.foreach.top_goods.iteration<4}--> <li class="topimg"> <a href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="samllimg" /></a> </li> <!-- {/if} --> <li {if $smarty.foreach.top_goods.iteration<4}class="iteration1"{/if}> <a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.short_name}</a><br /> {$lang.shop_price}<font class="f1">{$goods.price}</font><br /> </li> </ul> <!-- {/foreach} -->
Copyright © 2009-2019 Ywcms.Com All Right Reserved. 湘ICP备16006489号-2