关于显示ecshop最近几天最新发布商品的方法

2016-09-11 20:39 来源:www.chinab4c.com 作者:ecshop专家

1、在index.php的  assign_dynamic('index'); 上面写:

$smarty->assign('this_week_list',        get_this_week_list());

2、在index.php的最下面(?>上面)写:
function get_this_week_list(){

$today=getdate();
//今天
$day_this=local_strtotime($today['year']."-".$today['mon']."-".$today['mday']);
   //上周开始时间
       $lastweek_start_str=date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-date("w")+1-7,date("Y")));
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('goods') . " WHERE add_time>". $lastweek_start_str." and is_delete=0  and is_on_sale = 1 order by add_time desc limit 0,15";
$arr = $GLOBALS['db']->getAll($sql);
return $arr;
}

3、在index.dwt模板中写:
<!--{foreach from=$this_week_list item=value key=key}-->
<a href="goods.php?id={$value.goods_id}" ><img src="{$value.goods_thumb}"></a>

<!--{/foreach}-->


这样就OK了。