您现在的位置是:首页 > 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}-->

本文标签:

很赞哦! ()

相关源码

  • (自适应响应式)蓝色外贸英文产品介绍展示网站模板本模板采用手工编写的DIV+CSS架构,代码精简高效。适配手机端浏览,数据实时同步更新。内置SEO优化框架,支持独立设置各页面标题、关键词及描述。开源代码结构清晰,便于二次开发。查看源码
  • (带手机版)绿色生态农业种植农产品网站pbootcms源码下载本模板基于PbootCMS内核开发,为生态农业企业量身打造,适用于农业种植、有机农场、农产品电商等业务场景。模板设计充分体现绿色环保理念,突出农业特色,同时保持简洁大气的视觉效果,帮助农业企业建立专业形象。查看源码
  • (自适应)帝国cms7.5文章新闻博客整站源码( 带会员中心)本模板基于帝国CMS内核开发,为新闻资讯、个人博客及作品展示类网站设计。采用响应式布局技术,确保在手机、平板和电脑等不同设备上都能获得良好的浏览体验。查看源码
  • (自适应)中英双语配线器材扎带线卡网站pbootcms模板免费下载为线缆管理、电气配线领域打造的响应式网站模板,采用PbootCMS内核开发,可快速搭建企业级产品展示平台,数据实时同步管理。查看源码
  • (自适应响应式)高端网站建设设计公司互联网营销网站pbootcms模板本模板基于PbootCMS内核开发,为网站建设公司和互联网营销企业量身打造。采用响应式设计,适配各种移动设备,提供统一的后台管理体验查看源码
  • (PC+WAP)楼承板建筑工程合金钢铁材料pbootcms网站源码下载为楼承板生产商及建筑工程企业设计的响应式网站模板,采用PbootCMS内核开发,同步适配电脑与移动设备浏览。通过模块化结构展示工程案例、产品参数等专业内容,帮助建筑建材企业建立标准化数字展示平台,提升行业专业形象。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐