大家都知道ECSHOP首页的推荐、热卖和新品三个板块的商品都是从所有商品里读取出来的。
. i% c% T6 s' v' ~8 k如果我想“在ecshop首页调用指定分类的推荐、热卖和新品?”该怎么办呢,
/ C% h" D: U' T下面教你一种方法. 找到ecshop的includes/lib_goods.php,
8 E0 |5 A( {. e i& [" @$ ~把SQL语句改一下,与category表关联即可 将 $sql = 'SELECT g.goods_id,g.goods_name, g.goods_name_style,% \3 G' u- o" V0 w+ N' B
g.market_price, g.shop_price AS org_price, g.promote_price, ' . 修改为 $sql = 'SELECT g.goods_id,g.cat_id,c.parent_id,g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . 继续找到
Q! S& O6 K2 Z5 h7 E'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . 在它下面加一句
$ r) X% d% W d8 x, ?'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON c.cat_id = g.cat_id ' . 然后将% ?+ S7 g3 b* O
if (!empty($cats))# U5 o; l8 K% P) n% c
{ e" t6 b8 A$ p# _) h
$sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) .")";- k/ }0 B: k$ G3 I7 k4 a9 ~) [3 H; V
} 改为
i& x- q( W7 s, F, L0 k; {if (!empty($cats))
0 i: i! O8 q4 n! o: X {
6 ~- `) j% W9 X: l $sql .= " AND (c.parent_id =" . $cats. " OR " . get_extension_goods($cats) .")";
: _: f) |+ k/ u4 x4 q5 q/ ~ } 这个是和分类表建立关联,调出商品所在分类的上级分类1 o! N M# J) E+ M n) ?8 q" \
然后在index.php中增加下面代码
9 A5 o/ {" I- s. D$smarty->assign('chot_goods_35', get_category_recommend_goods('hot','35')); //指定分类下的热销商品 注意这个35是一级分类的ID,然后在模板中调用即可
+ a' O9 ?. M' N; L1 o4 {1 Y<!--{foreach from=$chot_goods_35 item=goods}-->2 _, D' U: ~ L7 x: Y+ @
<div style="padding-top: 8px;" class="new-tr">
! O" G1 g% y2 h: s" c <a target="_blank" href="{$goods.url}"><img width="116" height="130" border="0" alt="{$goods.name|escape:html}" src="{$goods.thumb}"></a>2 c" I! A& V& c$ w3 w+ o) q
<div class="right">
; ~% L7 e( K P- L9 q* u <a target="_blank" href="{$goods.url}">{$goods.name|escape:html}</a><br>
- O$ t, k r- G0 }9 N1 m1 @$ p6 ?$ k <span style="color: rgb(102, 102, 102); text-decoration: line-through;">市场价:{$goods.market_price}</span><br>4 Z" `9 I$ [3 O8 J8 l$ o- x
特卖价:<span style="color: rgb(255, 0, 0);">{$goods.shop_price}</span><br>
: u- D" P+ F$ a" U; v& E <span class="font-gmm"><a href="javascript:addToCart({$goods.id})">立即抢购</a></span> V0 e; ^7 b. |% d; I/ n ~
</div>
' i- D5 E0 j) \; }9 M <span class="new-line"></span>/ w5 B/ ~* O' U0 t6 @
</div>
) M) G2 P5 M# M* H. E- g+ w. ^ <!--{/foreach}-->
$ B! l* m4 b/ j; V7 }+ o" p' ]同理,新品,推荐都可以调,只要把hot改为new 或者best就可以了
1 W3 H, Y/ g3 a+ U* j' s |