目前很多商城网站上的第一楼和第二楼等都有显示某一级栏目下(父类别)所有的子栏目(子类别)的最新商品。根据客户网站的需求,长沙做网站的站长在好朋友的指导下,实现了该功能;下面列出方法供大家参考:
步骤【1】:
文件位置:includes/lib_goods.php
/** *根据类别ID获取最新商品(按商品序号倒序排列) * @param int $limit */ function get_latest_goods_by_category($catid,$limit){ $sql="SELECT goods_id,goods_name,goods_thumb,ROUND(shop_price,0) AS `price` FROM ecs_goods WHERE cat_id IN(SELECT cat_id FROM `ecs_category` WHERE parent_id=".$catid.") AND is_on_sale=1 ORDER BY goods_id DESC LIMIT ".$limit; return $GLOBALS['db']->getAll($sql);
步骤【2】:
文件位置:index.php
$smarty->assign('latest_goods_1', get_latest_goods_by_category(1,5)); //指定分类名称 $smarty->assign('latest_goods_2', get_latest_goods_by_category(2,5)); //指定分类名称2
latest_goods_1,latest_goods_2是需要调用的;
get_latest_goods_by_category(1,5)里的(1,5),1代表分类id;5代表获取5条数据。
步骤【3】:
文件位置:index.dwt
<!-- #BeginLibraryItem "/library/recommend_one.lbi" --><!-- #EndLibraryItem -->
recommend_one.lbi这个文件库是根据自己需求命名。
步骤【4】:
在library里新增这个库recommend_one.lbi
<!-- {if 1 eq 1} --> <!-- {if $cat_rec_sign neq 1} --> <div class="index_class_top"> <h1 class="title02"></h1> <ul> <li> <!--{foreach from=$categories.2.cat_id item=lower}--> <a href="{$lower.url}" title="{$lower.name|escape:html}" target="_blank">{$lower.name|escape:html}</a> | <!--{/foreach}--> </li> </ul> <span><a href="category.php?id=2" target="_blank">更多</a></span> </div> <div class="index_class_content"> <div class="class_content_area"> <ul> <!-- {/if} --> <!--{foreach from=$latest_goods_1 item=goods}--> <li> <a href="goods.php?id={$goods.goods_id}" target="_blank"><img src="{$goods.goods_thumb}" alt="{$goods.goods_name}" width="180" height="210" border="0" /></a> <dl class="detail"> <dt class="name"><a href="goods.php?id={$goods.goods_id}" title="{$goods.goods_name}" target="_blank">{$goods.goods_name}</a></dt> <dd><span class="price-irubao-label">市场价:<span class="price-irubao">¥{$goods.price}</span></span></dd> </dl> </li> <!--{/foreach}--> <!-- {if $cat_rec_sign neq 1} --> </ul> </div> </div> <!-- {/if} --> <!-- {/if} -->
latest_goods_1的1或者2,对应步骤2,不多解释。
Copyright © 2009-2019 Ywcms.Com All Right Reserved. 湘ICP备16006489号-2