求助:怎么把二级分类的商品分类树category_tree.lbi改成3J分类的

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家



下面是我现在的二级分类的商品分类树category_tree.lbi的代码,求高手给我修改成3J分类的商品分类树,先谢谢了。
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="catehome" id="category_home">
<ul>

<!--{foreach from=$categories item=cat}-->

<li class="parentCat">
<a href="{$cat.url}" class="cateone">{$cat.name|escape:html}</a>
<div class="catetwo">

<h4><a href="{$cat.url}">All Subcategories within {$cat.name|escape:html}</a><span class="cate_new"></span></h4>

<!--{foreach from=$cat.cat_id item=child name=child_cat}-->
{if $smarty.foreach.child_cat.index % 2 eq 0 || $smarty.foreach.child_cat.first}
<dl>
{/if}
<dt><a href="{$child.url}">{$child.name|escape:html}</a></dt>
{if $smarty.foreach.child_cat.index % 2 eq 1 || $smarty.foreach.child_cat.last}
</dl>
{/if}

<!--{/foreach}-->


</div>
</li>

<!--{/foreach}-->


</ul>
</div>

回答:
自己顶,在线等高手回复。

改下程序
/**
* 获得指定分类同级的所有分类以及该分类下的子分类
*
* @accesspublic
* @paraminteger$cat_id分类编号
* @returnarray
*/
function get_categories_tree($cat_id = 0)
{
if ($cat_id > 0)
{
$sql = 'SELECT parent_id FROM ' . $GLOBALS['pon']->table('category') . " WHERE cat_id = '$cat_id'";
$parent_id = $GLOBALS['db']->getOne($sql);
}
else
{
$parent_id = 0;
}

/*
判断当前分类中全是是否是底级分类,
如果是取出底级分类上级分类,
如果不是取当前分类及其下的子分类
*/
$sql = 'SELECT count(*) FROM ' . $GLOBALS['pon']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
if ($GLOBALS['db']->getOne($sql) || $parent_id == 0)
{
/* 获取当前分类及其子分类 */
$sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' .
'FROM ' . $GLOBALS['pon']->table('category') .
"WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";

$res = $GLOBALS['db']->getAll($sql);

foreach ($res AS $row)
{
if ($row['is_show'])
{
$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 (isset($row['cat_id']) != NULL)
{
$cat_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
}
}
}
}
if(isset($cat_arr))
{
return $cat_arr;
}
}

function get_child_tree($tree_id = 0)
{
$three_arr = array();
$sql = 'SELECT count(*) FROM ' . $GLOBALS['pon']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 ";
if ($GLOBALS['db']->getOne($sql) || $tree_id == 0)
{
$child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
'FROM ' . $GLOBALS['pon']->table('category') .
"WHERE parent_id = '$tree_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_arr[$row['cat_id']]['id']= $row['cat_id'];
$three_arr[$row['cat_id']]['name'] = $row['cat_name'];
$three_arr[$row['cat_id']]['url']= build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);

if (isset($row['cat_id']) != NULL)
{
$three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);

}
}
}
return $three_arr;
}

<!--{foreach from=$child.cat_id item=childer}-->
<dd>&nbsp;&nbsp;<a href="{$childer.url}">{$childer.name|escape:html}</a></dd>
<!--{/foreach}-->

没错,好棒。