方法一、已测试成功
1、在/includes/lib_goods.php最底部增加以下代码

1 function index_get_cat_id_goods_best_list($cat_id = '', $num = '') 2 { 3 $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, ' . 4 "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". 5 "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, " . 6 "g.is_best, g.is_new, g.is_hot, g.is_promote " . 7 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 8 'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON c.cat_id = g.cat_id ' . 9 "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". 10 "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". 11 "Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ". 12 $sql .= " AND (c.parent_id =" . $cat_id. " OR g.cat_id = " . $cat_id ." OR g.cat_id ". db_create_in(array_unique(array_merge(array($cat_id), array_keys(cat_list($cat_id, 0, false))))) .")"; 13 $sql .= " LIMIT $num"; 14 $res = $GLOBALS['db']->getAll($sql); 15 $goods = array(); 16 foreach ($res AS $idx => $row) 17 { 18 $goods[$idx]['id'] = $row['article_id']; 19 $goods[$idx]['id'] = $row['goods_id']; 20 $goods[$idx]['name'] = $row['goods_name']; 21 $goods[$idx]['brief'] = $row['goods_brief']; 22 $goods[$idx]['brand_name'] = $row['brand_name']; 23 $goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); 24 $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? 25 sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; 26 $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']); 27 $goods[$idx]['market_price'] = price_format($row['market_price']); 28 $goods[$idx]['shop_price'] = price_format($row['shop_price']); 29 $goods[$idx]['thumb'] = empty($row['goods_thumb']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_thumb']; 30 $goods[$idx]['goods_img'] = empty($row['goods_img']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_img']; 31 $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); 32 } 33 return $goods; 34 }
2、在index.php文件的分配smarty处增加以下代码
$smarty->assign('cat_id16_best_goods', index_get_cat_id_goods_best_list(16,8)); //其中16是你调用的分类的id,这个分类可以是一级,也可以是二级。8是你要调用的条数。
3、在library文件夹下新建一个名为index_category.lbi并输入以下代码

1 <!--{foreach from=$cat_id16_best_goods item=goods}--> 2 <div > 3 <img src="{$goods.thumb}" width="148" height="148" /></div> 4 <div><A title={$goods.name|escape:html} href="{$goods.url}" target=_blank>{$goods.short_name|truncate:8:true}</A></div> 5 <div>市场价:{$goods.market_price}元</div> 6 <div>本店价:{$goods.shop_price}元</div> 7 <div>售出:{$lang.order_number}件</div> 8 </div> 9 <!-- { /foreach }-->
4、在首页模板index.dwt中,在你想显示的位置加上以下代码
<!-- #BeginLibraryItem "/library/index_category.lbi" --><!-- #EndLibraryItem -->
方法二、未测试
1、在后台:模板管理->模板设置->首页模板->分类下的商品设置显示条数
2、下面的15代码分类id,既你要调用哪个分类的产品,就写几
1 <?php $this->assign(’cat_goods’,$this->_var['cat_goods_15']); ?><?php $this->assign(’goods_cat’,$this->_var['goods_cat_15']); ?><?php echo $this->fetch(’library/cat_goods.lbi’); ?>
方法三、和方法二差不多
1、先在index.dwt文件中加入<!– TemplateBeginEditable name=”手机” –><!– TemplateEndEditable –>
2、在后台:模板管理->模板设置->首页模板->分类下的商品->点下+号->然后在左下拉框点手机->右下拉框点你想要调用的分类->这个分类的样式就是cat_goods.lbi文件中的样式
方法四、和方法二和三差不多
下面的14代码分类id
1 <!–{foreach from=$cat_goods_14 item=goods}–> 2 <div> 3 <div><a href=”{$goods.url}” target=”_blank”><img src=”{$goods.thumb}” alt=”{$goods.name|escape:html}” width=”67″ height=”56″ border=”0″ class=”imgb”/></a></div> 4 <div><a href=”{$goods.url}” target=”_blank”>{$goods.short_name|escape:html|truncate:10}</a><br /> 5 <span>{$goods.shop_price}</span></div> 6 </div> 7 <!–{/foreach}–>