您现在的位置是:首页 > cms教程 > Ecshop商城教程Ecshop商城教程

ecshop商品分类显示商品分类菜单的方法

依珊2024-01-16Ecshop商城教程已有人查阅

导读ecshop商品分类页面获得当前分类的子分类和 分类教程: 步:修改/include/lib_goods.php,在第24行加入以下代码:/*** 获得指

ecshop商品分类页面获得当前分类的子分类和 分类教程:
步骤一:修改/include/lib_goods.php,在第24行加入以下代码:
/**
* 获得指定分类下的子分类
*
* @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函数,更具$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));
如果想用不同的颜 表示出当前点击的分类和其他分类,那么还要保留当前点击的分类id。再加一行:
$smarty->assign('current_cat_id',
$cat_id);
​​​​​​​//当前的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}">
<!--{if $current_cat_id eq $child.id} 显示当前点击的分类为橙 -->
<span style="color:#ff6600">
<!--{/if}-->· {$child.name|escape:html}<!--{if $current_cat_id eq $child.id}--></span>
<!--{/if}-->
</a>
<!--{foreachelse}-->
· 没有分类了!
<!--{/foreach}-->
<!--{/foreach}-->

本文标签:

很赞哦! ()

相关源码

  • (自适应)酒店民宿客房旅馆pbootcms模板下载基于PbootCMS内核开发的酒店民宿行业专用网站模板,专注于为住宿服务企业提供专业高效的在线展示平台。该模板采用响应式设计结构,确保在不同终端设备上均能呈现优质浏览体验。查看源码
  • pbootcms模板(PC+WAP)火锅加盟餐饮美食类带留言源码基于PbootCMS内核深度开发,为火锅、餐饮品牌打造的营销型解决方案。采用红色主题传递行业活力,实现PC与WAP端适配。查看源码
  • (自适应)平面设计网络工作室个人作品展示网站模板免费下载基于PbootCMS内核开发的响应式网站模板,为设计工作室、创意机构打造的作品展示解决方案。通过模块化布局与极简交互设计,呈现设计作品的视觉细节,支持作品分类、案例解析等多维度展示方式。查看源码
  • 响应式茶叶茶道pbootcms网站模板源码(自适应手机端)棕色复古茶具主题的响应式网站模板,为茶叶茶道企业设计,同时支持古玩字画、艺术文化等行业的快速适配,通过替换文字图片即可转型为其他行业官网,大幅降低开发成本。查看源码
  • (自适应)蓝色厨卫厨房水龙头阀门水槽设备源码下载基于PbootCMS内核开发,深度适配厨卫设备行业特性。通过精准的产品展示模块与水效标识专区设计,有效呈现五金件工艺细节。响应式布局确保从手机到平板都能展示金属质感与水流动态效果。查看源码
  • (自适应)黑色摄影作品工作室pbootcms模板网站源码下载为风景摄影、个人工作室打造的高端网站模板,基于PbootCMS开源内核开发,采用HTML5自适应架构,PC与移动端实时数据同步,适配各类拍摄作品展示需求。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐