最近研究ecshop,给一个朋友用ECSHOP套一个网店,需 要调用商品指定分类下级分类 翻遍互联网 没有找到想要的。决定自己动手搞定,(果然自己动手丰衣足食呀)
现在把代码贴贴出来分享一下
打开 //**lib_goods.php 最后加上
//*** 调用商品分类指定分类下级分类
function get_parent_id_tree($parent_id)
{
$three_c_arr = array();
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
if ($GLOBALS['db']->getOne($sql))
{
$child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
'FROM ' . $GLOBALS['ecs']->table('category') .
"WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
$res = $GLOBALS['db']->getAll($child_sql);
foreach ($res AS $row)
{
if ($row['is_show'])
$three_c_arr[$row['cat_id']]['id'] = $row['cat_id'];
$three_c_arr[$row['cat_id']]['name'] = $row['cat_name'];
$three_c_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
}
}
return $three_c_arr;
}
声明后用$smarty调用
$smarty->assign('get_parent_id6_tree', get_parent_id_tree(6));//调用父级分类6的下级分类
然后就可以在dwt模板文件里开始调用了
<!--{foreach from=$get_parent_id6_tree item=list}-->
<li>
<a href="{$list.url}" title="{$list.name|escape:html}">{$list.name|truncate:15:true}</a>
</li>
<!--{/foreach}-->
终于解决了,兴奋啊~~~~~