商品分类三级不显示怎么回事 ecshop
代码:<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"><h1class="mod3tit"...
代码:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><h1 class="mod3tit" style="background: url(images/category_tree_bg.gif) repeat-x;"><a href="catalog.php" style=" color: #fff">{$lang.all_category}</a></h1><div class="mod1 mod2 blank" id="historybox" > <span class="lb"></span><span class="rb"></span><div class="cagegoryCon clearfix"><!--{foreach from=$categories item=cat}--> <dl> <dt><a href="{$cat.url}">{$cat.name|escape:html}</a></dt> <!--{if $cat.cat_id}--> <dd class="clearfix"> <!--{foreach name=childs from=$cat.cat_id item=child}--> <p onMouseOver="this.className='itemsbg'" onMouseOut="this.className=''"><a href="{$child.url}" title="{$child.name|escape:html}" class="txtdot">{$child.name|escape:html}</a></p> <!--{/foreach}--> </dd> <!--{/if}--> </dl> <!--{/foreach}--></div><div class="blank"></div></div>
我想改成这样效果的 展开
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><h1 class="mod3tit" style="background: url(images/category_tree_bg.gif) repeat-x;"><a href="catalog.php" style=" color: #fff">{$lang.all_category}</a></h1><div class="mod1 mod2 blank" id="historybox" > <span class="lb"></span><span class="rb"></span><div class="cagegoryCon clearfix"><!--{foreach from=$categories item=cat}--> <dl> <dt><a href="{$cat.url}">{$cat.name|escape:html}</a></dt> <!--{if $cat.cat_id}--> <dd class="clearfix"> <!--{foreach name=childs from=$cat.cat_id item=child}--> <p onMouseOver="this.className='itemsbg'" onMouseOut="this.className=''"><a href="{$child.url}" title="{$child.name|escape:html}" class="txtdot">{$child.name|escape:html}</a></p> <!--{/foreach}--> </dd> <!--{/if}--> </dl> <!--{/foreach}--></div><div class="blank"></div></div>
我想改成这样效果的 展开
2个回答
展开全部
ecshop系统默认的获得分类方法,只能获得跟分类同级的分类,如果想在分类页面获得其子分类和三级分类的需要按照下面步骤修改代码
第一步:修改/include/lib_goods.php,在第24行加入以下代码:
/**
* 获得指定分类下的子分类
*
* @access public
* @param integer $cat_id 分类编号
* @return array
*/
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'] != NULL)
{
$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函数,更具$cat_id来得到当前分类所有的分类
第二步,修改/category.php,找到122行,原先的代码是:
$smarty->assign('categories', get_categories_tree($cat_id)); // 分类树
这其实是模板技术,如果你想彻底抛弃原来的分类样式,那么把get_categories_tree($cat_id)换成刚才
我们自定义的函数get_children_tree($cat_id)
如果你想保留原先的分类功能,再新增自定义的分类功能,那么在122行下面再新增一行:
$smarty->assign('categories2', get_children_tree($cat_id));
最后一步修改category.dwt。
你要根据第二部定义的模板变量来写:到底是categories还是categories2,更具你实际情况来定。我这
里是categories2:
<!--{foreach from=$categories item=cat}-->
{$cat.name|escape:html} <!--这个就是你点击的分类,下面都是他的子类-->
<!--{foreach from=$cat.children item=child}-->
<a href="{$child.url}">
<span style="color:#ff6600">· {$child.name|escape:html}</a>
<!--{foreachelse}-->
· 没有分类了!
<!--{/foreach}-->
<!--{/foreach}-->
第一步:修改/include/lib_goods.php,在第24行加入以下代码:
/**
* 获得指定分类下的子分类
*
* @access public
* @param integer $cat_id 分类编号
* @return array
*/
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'] != NULL)
{
$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函数,更具$cat_id来得到当前分类所有的分类
第二步,修改/category.php,找到122行,原先的代码是:
$smarty->assign('categories', get_categories_tree($cat_id)); // 分类树
这其实是模板技术,如果你想彻底抛弃原来的分类样式,那么把get_categories_tree($cat_id)换成刚才
我们自定义的函数get_children_tree($cat_id)
如果你想保留原先的分类功能,再新增自定义的分类功能,那么在122行下面再新增一行:
$smarty->assign('categories2', get_children_tree($cat_id));
最后一步修改category.dwt。
你要根据第二部定义的模板变量来写:到底是categories还是categories2,更具你实际情况来定。我这
里是categories2:
<!--{foreach from=$categories item=cat}-->
{$cat.name|escape:html} <!--这个就是你点击的分类,下面都是他的子类-->
<!--{foreach from=$cat.children item=child}-->
<a href="{$child.url}">
<span style="color:#ff6600">· {$child.name|escape:html}</a>
<!--{foreachelse}-->
· 没有分类了!
<!--{/foreach}-->
<!--{/foreach}-->
展开全部
首先你这段代码里没有三级分类循环
<!--{foreach name=childs from=$cat.cat_id item=child}-->
<p onMouseOver="this.className='itemsbg'" onMouseOut="this.className=''"><a href="{$child.url}" title="{$child.name|escape:html}" class="txtdot">{$child.name|escape:html}</a></p>
<!--{/foreach}-->
这里是二级分类循环,如果要加三级分类,直接将代码改成
<!--{foreach name=childs from=$cat.cat_id item=child}-->
<p onMouseOver="this.className='itemsbg'" onMouseOut="this.className=''"><a href="{$child.url}" title="{$child.name|escape:html}" class="txtdot">{$child.name|escape:html}</a></p>
<!--{foreach from=$cat.cat_id item=child}-->
<a href="{$child.url}">{$child.name|escape:html}</a>
<!--{/foreach}-->
<!--{/foreach}-->
这样既可
<!--{foreach name=childs from=$cat.cat_id item=child}-->
<p onMouseOver="this.className='itemsbg'" onMouseOut="this.className=''"><a href="{$child.url}" title="{$child.name|escape:html}" class="txtdot">{$child.name|escape:html}</a></p>
<!--{/foreach}-->
这里是二级分类循环,如果要加三级分类,直接将代码改成
<!--{foreach name=childs from=$cat.cat_id item=child}-->
<p onMouseOver="this.className='itemsbg'" onMouseOut="this.className=''"><a href="{$child.url}" title="{$child.name|escape:html}" class="txtdot">{$child.name|escape:html}</a></p>
<!--{foreach from=$cat.cat_id item=child}-->
<a href="{$child.url}">{$child.name|escape:html}</a>
<!--{/foreach}-->
<!--{/foreach}-->
这样既可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询