/**
* 獲得指定分類下的子分類
*
* @access ?public
* @param ? integer ? ? $cat_id ? ? 分類編號
* @return ?array
*www.ebingou.cn
*/
function get_children_tree($cat_id)
{
if ($cat_id >0 )
{
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$cat_id'";
//$cot = $GLOBALS['db']->getOne($sql);
if ($GLOBALS['db']->getOne($sql))
{
// 獲取當前分類名及其子類
$sql = 'SELECT a.cat_id, a.cat_name, a.sort_order AS parent_order, a.cat_id, ' .
'b.cat_id AS child_id, b.cat_name AS child_name, b.sort_order AS child_order ' .
'FROM ' . $GLOBALS['ecs']->table('category') . ' AS a ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS b ON b.parent_id = a.cat_id ' .
"WHERE a.cat_id = '$cat_id' ORDER BY parent_order ASC, a.cat_id ASC, child_order ASC";
}
else
{
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'";
$parent_id = $GLOBALS['db']->getOne($sql);
if ($parent_id > 0)
{
//獲取當前分類、兄弟及其父類
$sql = 'SELECT a.cat_id, a.cat_name, b.cat_id AS child_id, b.cat_name AS child_name, b.sort_order ' .
'FROM ' . $GLOBALS['ecs']->table('category') . ' AS a ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS b ON b.parent_id = a.cat_id ' .
"WHERE b.parent_id = '$parent_id' ORDER BY sort_order ASC";
}
else
{
//獲取當前分類
$sql = 'SELECT a.cat_id, a.cat_name FROM '
. $GLOBALS['ecs']->table('category') . ' AS a ' .
"WHERE a.cat_id = '$cat_id'";
}
}
$res = $GLOBALS['db']->getAll($sql);
$cat_arr = array();
foreach ($res AS $row)
{
$cat_arr[$row['cat_id']]['id'] = $row['cat_id'];
$cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
$cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
if ($row['child_id'] !NULLbr /> ? ? ? ? {
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['id'] = $row['child_id'];
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['name'] = $row['child_name'];
$cat_arr[$row['cat_id']]['children'][$row['child_id']]['url'] = build_uri('category', array('cid' => $row['child_id']), $row['child_name']);
}
}
return $cat_arr;
}
}
這其實就是一個get_children_tree函數(shù),更具$cat_id來得到當前分類所有的分類
$smarty->assign('categories', get_categories_tree($cat_id)); // 分類樹
這其實是模板技術,如果你想 拋棄原來的分類樣式,那么把get_categories_tree($cat_id)換成剛才我們自定義的函數(shù)get_children_tree($cat_id)
$smarty->assign('categories2', get_children_tree($cat_id));
如果想用不同的顏 表示出當前點擊的分類和其他分類,那么還要保留當前點擊的分類id。再加一行:
$smarty->assign('current_cat_id',
$cat_id);
???????//當前的id
最后一步修改category.dwt。
{$cat.name|escape:html}
· {$child.name|escape:html}
· 沒有分類了!
版權聲明: 本站資源均來自互聯(lián)網或會員發(fā)布,如果侵犯了您的權益請與我們聯(lián)系,我們將在24小時內刪除!謝謝!
轉載請注明: ecshop商品分類顯示商品分類菜單的方法