欢迎来到素材无忧网,按 + 收藏我们
登录 注册 退出 找回密码

ecshop导航栏使用二级菜单显示并调用商品子分类

时间: 2024-02-25 10:42 阅读: 作者:素材无忧网

在includes/cls_template.php里顶部插入分类函数代码:
//通过参数判断是否存在二级分类
function get_subcate_byurl($url)
{
$rs = strpos($url,"category");
if($rs!==false)
{
preg_match("/d+/i",$url,$matches);
$cid = $matches[0];
$cat_arr = array();
$sql = "select * from ".$GLOBALS['ecs']->table('category')." where parent_id=".$cid." and is_show=1 ORDER BY sort_order ASC, cat_id ASC";
$res = $GLOBALS['db']->getAll($sql);
foreach($res as $idx => $row)
{
$cat_arr[$idx]['id']   = $row['cat_id'];
$cat_arr[$idx]['name'] = $row['cat_name'];
$cat_arr[$idx]['url']  = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
$cat_arr[$idx]['children'] = get_clild_list($row['cat_id']);
}
return $cat_arr;
}
else
{
return false;
}
}
function get_clild_list($pid)
{
//开始获取子分类
$sql_sub = "select * from ".$GLOBALS['ecs']->table('category')." where parent_id=".$pid." and is_show=1 ";
$subres = $GLOBALS['db']->getAll($sql_sub);
if($subres)
{
foreach ($subres as $sidx => $subrow)
{
$children[$sidx]['id']=$subrow['cat_id'];
$children[$sidx]['name']=$subrow['cat_name'];
$children[$sidx]['url']=build_uri('category', array('cid' => $subrow['cat_id']), $subrow['cat_name']);
}
}
else
{
$children = null;
}
return $children;
}
接下来呢,ecshop中的模板文件,也就是thems,找到你自己的模板文件夹,我就使用默认的说好了,打开themesdefaultlibrarypage_header.lbi文件
找到ecshop的导航条模板文件代码,也就是以下代码:
  • {$lang.home}
  • {$nav.name}
  • 在代码中加入一段调用分类的代码,位置看你如何构思二级分类的表现,我是直接这样加的,我是直接使用鼠标移到或移出当前栏目名称时,更改当前栏目标签的CLASS名称和CSS样式结合达到二级栏目的显示和隐藏的:
  • {$lang.home}
  • CSS样式的表现思路:我通过鼠标移入移出改变当前li标签的CLASS名称,当鼠标移到上面时,CLASS为"menu1",当鼠标移出时,则变 回"menu2",在li下的div层的显示和隐藏就决定该DIV的父层li 的CLASS名是"menu1"还是"menu2"了,2为隐藏,1为显示,具体就这样了,还看不懂的可以留言给我

    版权声明: 本站资源均来自互联网或会员发布,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!

    转载请注明: ecshop导航栏使用二级菜单显示并调用商品子分类

    标签: ecshop导航  
    推荐文章
    模板推荐