百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>Ecshop教程> ecshop首页调用指定分类的所有产品(指定一级调
分享文章到:

ecshop首页调用指定分类的所有产品(指定一级调

发布时间:12/03 来源: 浏览: 关键词:

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_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') . ' 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_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 ($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'] = 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;
}

 

第二:在index.php增加

 

$smarty->assign('cat_id16_best_goods', index_get_cat_id_goods_best_list(16,3));

 

cat_id16_best_goods 红色改为你指定的ID
index_get_cat_id_goods_best_list(16,3) 红色你指定的一级栏目ID 蓝色为调用的条数

 

<!--{foreach from=$cat_id16_best_goods item=goods}-->
<ul>
<li class="cat_img">
<a href="{$goods.url}" title="" target="_blank"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" width="100" height="100" /></a>
</li>
<li><a href="{$goods.url}" target="_blank" title="{$goods.name|escape:html}">{$goods.short_name|truncate:8:true}</a></li>
<li><span>{$goods.shop_price}</span></li>
</ul>
<!-- { /foreach }-->

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

相关文章

共有5人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板