ecshop调用指定商品分类下的商品

2025-04-19 19:37:56

1、在系统目录文件找到includes/lib_goods.php这个文件打开在此页最鹊奁夭肢底部加入以下函数代码:/***首页获取指定分类产品**@a艘早祓胂ccesspublic*@paramstring$cat_id53_best_goods*@paramarray$cat_id53_best_goods*@returnarray*/functionget_cat_id_goods_list($cat_id='',$num=''){$sql='Selectg.goods_id,g.cat_id,c.parent_id,g.goods_name,g.goods_name_style,g.market_price,g.shop_priceASorg_price,g.promote_price,'."IFNULL(mp.user_price,g.shop_price*'$_SESSION[discount]')ASshop_price,"."promote_start_date,promote_end_date,g.goods_brief,g.goods_thumb,goods_img,"."g.is_best,g.is_new,g.is_hot,g.is_promote".'FROM'.$GLOBALS['ecs']->table('goods').'ASg'.'LEFTJOIN'.$GLOBALS['ecs']->table('category').'AScONc.cat_id=g.cat_id'."LEFTJOIN".$GLOBALS['ecs']->table('member_price')."ASmp"."ONmp.goods_id=g.goods_idANDmp.user_rank='$_SESSION[user_rank]'"."Whereg.is_on_sale=1ANDg.is_alone_sale=1ANDg.is_delete=0".$sql.="AND(c.parent_id=".$cat_id."ORg.cat_id=".$cat_id."ORg.cat_id".db_create_in(array_unique(array_merge(array($cat_id),array_keys(cat_list($cat_id,0,false))))).")";$sql.="LIMIT$num";$res=$GLOBALS['db']->getAll($sql);$goods=array();foreach($resas$idx=>$row){$goods[$idx]['id']=$row['article_id'];$goods[$idx]['id']=$row['goods_id'];$goods[$idx]['name']=$row['goods_name'];$goods[$idx]['brief']=$row['goods_brief'];$goods[$idx]['brand_name']=$row['brand_name'];$goods[$idx]['goods_style_name']=add_style($row['goods_name'],$row['goods_name_style']);$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]['short_style_name']=add_style($goods[$idx]['short_name'],$row['goods_name_style']);$goods[$idx]['market_price']=price_format($row['market_price']);$goods[$idx]['shop_price']=price_format($row['shop_price']);$goods[$idx]['thumb']=empty($row['goods_thumb'])?$GLOBALS['_CFG']['no_picture']:$row['goods_thumb'];$goods[$idx]['goods_img']=empty($row['goods_img'])?$GLOBALS['_CFG']['no_picture']:$row['goods_img'];$goods[$idx]['url']=build_uri('goods',array('gid'=>$row['goods_id']),$row['goods_name']);}return$goods;}

2、打开系统根目录下index.php文件加入如下代码,如果要在别的页面调用加到别的页面:$smarty->assign('cat_id_goods_list_86',get_cat_id_goods_list(86,9)); //指定商品调用//其中86指的调用的栏目ID,9指的是调用商品的数量。

3、在首页模版中调用即可,如下:<!--{foreachfrom=$cat_id娄多骋能_goods_list_86item=goods}--><li>   <a href=媪青怍牙"{$goods.url}" target="_blank"> <img src="{$goods.thumb}" alt="{$goods.name|escape:html}" /></a> <span class="a_title"> <a href="{$goods.url}" title="{$goods.name|escape:html}" target="_blank"> {$goods.short_style_name}</a> </span> <div style="text-indent: 5px;">市场价 <span class="del">{$goods.market_price}</span></div> <div style="text-indent: 5px;"><span class="red">售 价 {$goods.shop_price}</span></div></li><!--{/foreach}-->

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:28
  • 阅读量:74
  • 阅读量:79
  • 阅读量:66
  • 阅读量:93
  • 猜你喜欢