ecshop调用制定分类下的分类
1、//在文件 includes/lib_goods.php最后加上
1 //*** 调用商品分类指定分类下级分类 2 function get_parentid_tree($parent_id) 3 { 4 $get_parentid_arr = array(); 5 $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 "; 6 if ($GLOBALS['db']->getOne($sql)) 7 { 8 $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' . 9 'FROM ' . $GLOBALS['ecs']->table('category') . 10 "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC"; 11 $res = $GLOBALS['db']->getAll($child_sql); 12 foreach ($res AS $row) 13 { 14 if ($row['is_show']) 15 $get_parentid_arr[$row['cat_id']]['id'] = $row['cat_id']; 16 $get_parentid_arr[$row['cat_id']]['name'] = $row['cat_name']; 17 $get_parentid_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); 18 } 19 } 20 return $get_parentid_arr; 21 }
、在index.php调用:$smarty->assign('get_parentid_tree1', get_parentid_tree(1));//调用父级分类为1的下级分类
3、最后在index.dwt中添加代码:
{foreach from=$get_parentid_tree1 item=loop}
{$loop.name|truncate:20:true}|
{/foreach}