ecshop首頁呼叫某一類別下的商品
測試可用
首先、我們再在/includes/lib_goods.php下增加如下程式碼:這個程式碼我加在了最底部:
function index_get_cat_id_goods_best_list($cat_id = '', $num = '')
{
$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, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
"promote_start_
"g.is_best, g.is_new, g.is_hot, g.is_promote " .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON c.cat_id = g.cat_id ' .
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
"Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ".
$sql .= " AND (c.parent_id =" . $cat_id. " OR g.cat_id = " . $cat_id ." OR g.cat_id ". db_create_in(array_
$sql .= " LIMIT $num";
$res = $GLOBALS['db']->getAll($sql);
$goods = array();
foreach ($res AS $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'] = a
$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;
}
第二、在index.php增加以下程式碼
$smarty->assign('cat_id16_best_goods', index_get_cat_id_goods_best_list(16,8));
其中16是你呼叫的分類的id,這個分類可以是一級,也可以是二級。要注意有兩個16
8是你要呼叫的條數。
第三、新增一個.lbi,新增如下程式碼 :我建立的名字是shounvxing.lib
<!--{foreach from=$cat_id16_best_goods item=goods}-->
<li>
<div ><img class="b1" src="{$goods.thumb}" width="148" height="148" /></div>
<div><A title={$goods.name|escape:html} href="{$goods.url}" target=_blank>{$goods.short_name|truncate:8:true}</A></div>
<div class="f_delline">市場價:{$goods.market_price}元 </div>
<div class="f_red">無憂康價:{$goods.shop_price}元</div>
<div class="f_orange">售出:{$lang.order_number}件</div>
<div></div>
</li>
<!-- { /foreach }-->
第四、在首頁模板index.dwt中,在你想顯示的位置加上以下程式碼:
<!-- #BeginLibraryItem "/library/shounvxing.lbi" --><!-- #EndLibraryItem -->