ecshop如何控制各级别分类的显示
2009-09-11 16:33 来源:www.chinab4c.com 作者:ecshop专家
/**
* 获得指定分类同级的所有分类以及该分类下的子分类
*
* @access public
* @param integer $cat_id 分类编号
* @return array
*/
function get_categories_tree($cat_id = 0)
{
if ($cat_id > 0)
{
$sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'";
$parent_id = $GLOBALS['db']->getOne($sql);
}
else
{
$parent_id = 0;
}
/*
判断当前分类中全是是否是底级分类,
如果是取出底级分类上级分类,
如果不是取当前分类及其下的子分类
*/
$where_child = '';
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
if ($GLOBALS['db']->getOne($sql) || $parent_id == 0)
{
/* 获取当前分类及其子分类 */
if($parent_id == 0) {
$sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' .
'FROM ' . $GLOBALS['ecs']->table('category') .
"WHERE parent_id = '$parent_id' AND is_show = 1 and cat_id = $cat_id ORDER BY sort_order ASC, cat_id ASC";
$where_child =" limit 5";
}else{
$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($sql);
foreach ($res AS $row)
{
if ($row['is_show'])
{
$cat_arr[$row['cat_id']]['id'] = $row['cat_id'];
$cat_arr[$row['cat_id']]['parent_id'] = $row['parent_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'], $where_child);
}
}
}
}
if(isset($cat_arr))
{
return $cat_arr;
}
}
function get_child_tree($tree_id = 0,$where_child)
{
$three_arr = array();
$sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->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['ecs']->table('category') .
"WHERE parent_id = '$tree_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC $where_child ";
$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']]['parent_id'] = $row['parent_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'],$where_child);
}
}
}
return $three_arr;
}
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="box">
<div class="box_1">
<div id="category_tree">
<!--{foreach from=$categories item=cat name = tt}-->
<!----------foreach循环中,增加一个name =tt。用来控制循环下标----->
<dl>
<dt><a href="{$cat.url}">{$cat.name|escape:html}</a></dt>
{assign var=foo value=$cat.id}
{assign var=parent_id value=$cat.parent_id}
<!----------将tt中的分类id---------->
{if $foo eq $category}
<!--{foreach from=$cat.cat_id item=child name = aa1}-->
<dd><a href="{$child.url}">{$child.name|escape:html}</a></dd>
<!--{foreach from=$child.cat_id item=childer name = aa2}-->
<dd> <a href="{$childer.url}">{$childer.name|escape:html}</a></dd>
<!--{/foreach}-->
{if $parent_id == 0}<br>
<a href="catalog.php">more</a>
{/if}
<!--{/foreach}-->
{else}
{assign var=m value=0}
<!--{foreach from=$cat.cat_id item=child name = aa1}-->
{if $smarty.foreach.aa1.iteration <= 5}
{assign var=m value=$smarty.foreach.aa1.iteration}
<dd><a href="{$child.url}">{$child.name|escape:html}</a></dd>
<!--{foreach from=$child.cat_id item=childer name = aa2}-->
<dd> <a href="{$childer.url}">{$childer.name|escape:html}</a></dd>
<!--{/foreach}-->
{/if}
<!--{/foreach}--><br>
{if $m == 5}
<a href="catalog.php">more</a>
{/if}
{/if}
</dl>
<!--{/foreach}-->
</div>
</div>
</div>
<div class="blank5"></div>
最近更新
常用插件
- 查看ecshop推荐人列表插件
ecshop这个系统是有推荐功能的。就是注册推荐,商品地址的推荐.来完...
- ecshop二次开发详细页面生
插件介绍: ECSHOP系统,在很多时候,很多商品没有人购买,不但购买的人...
- ecshop供应商插件
ecshop供应商插件,主要是通过对ecshop二次开发,在ecshop原来的供应商基...
- ecshop退款插件2.7.1utf版
ecshop退款插件2.7.1utf版重要可以通过会员中心,会员在收到货之后,发现...
- ecshop库存不足提示补货报
ecshop当库存不足,你需要提醒客服及时补充货物,而且每个缺货的商品...