1.在page_header.lbi对应的位置(你想显示导航的位置)插入

(注意下面的"themes/模板名称/util.php"中的"模板名称"改成你模板文件夹的名称)

  1. <?php
  2. require_once("themes/模板名称/util.php");
  3. ?>
  4. <div class="header-menu">
  5. <p {if $navigator_list.config.index eq 1} class="cur" {/if}><a href="../index.php">{$lang.home}</a></p>
  6. <ul>
  7. <!-- {foreach name=nav_middle_list from=$navigator_list.middle item=nav} -->
  8. <li onMouseOver="sw_nav(this,1);" onMouseOut="sw_nav(this,0);" {if $nav.active eq 1} class="curs"{/if}>
  9. <a href="{$nav.url}" {if $nav.opennew eq 1}target="_blank" {/if}>{$nav.name}</a>
  10. <?php
  11. $subcates = get_subcate_byurl($GLOBALS['smarty']->_var['nav']['url']);
  12. if($subcates!=false)
  13. {
  14. if(count($subcates)>0)
  15. {
  16. echo "<div class='sub_nav'>";
  17. if($subcates)
  18. {
  19. foreach($subcates as $cate)
  20. {
  21. echo "<a href='".$cate['url']."' class='level_1'>".$cate['name']."</a>";
  22. }
  23. }
  24. echo "</div><iframe frameborder='0' scrolling='no' class='nomask'></iframe>";
  25. }
  26. }
  27. ?>
  28. </li>
  29. <!-- {/foreach} -->
  30. </ul>
  31. <script type="text/javascript">
  32. //初始化主菜单
  33. function sw_nav(obj,tag)
  34. {
  35. var subdivs = obj.getElementsByTagName("DIV");
  36. var ifs = obj.getElementsByTagName("IFRAME");
  37. if(subdivs.length>0)
  38. {
  39. if(tag==1)
  40. {
  41. subdivs[0].style.display = "block";
  42. ifs[0].style.display = "block";
  43. }
  44. else
  45. {
  46. subdivs[0].style.display = "none";
  47. ifs[0].style.display = "none";
  48. }
  49. }
  50. }
  51. </script>
  52. </div>

2.在CSS文件中插入

  1. .header-menu p{ float:left;padding:1px 12px 1px 0;margin-top:-2px;}
  2. .header-menu  ul li{float:left;padding:1px 12px 1px 12px;margin-top:-2px;}
  3. .header-menu ul li a,.header-menu p a{color: #333;display:block;}
  4. .header-menu ul li a:hover,.header-menu p a:hover{color:#888;}
  5. .header-menu ul li.curs{background:#999;}
  6. .header-menu ul li.curs a{color:#fff;}
  7. .sub_nav{ background:#999;width:110px; position:absolute; z-index:5003; display:none;margin-left:-12px;}
  8. .nomask{ background:#fff; width:110px; height:50px; position:absolute; z-index:5002;display:none;margin-left:-12px;}
  9. .sub_nav a.level_1{ display:block;color:#fff;padding:6px 6px 6px 13px;font:11px Tahoma,Verdana,PMingLiU,Arial;border-bottom:1px dotted #D1D1D1;*border-bottom:1px dotted #D1D1D1 !important;*border-bottom:1px solid #A8A8A8;}
  10. .sub_nav a.level_1:hover{color:#fff;background:#55B46C;text-decoration:none;}

3.把以下代码编辑成(util.php)解压出来拷贝到模板目录下

    1. <?php
    2. /**
    3. * 通过传入参数的url判断是否为目录分类,从而获取子菜单
    4. *
    5. * @param string $url
    6. */
    7. function get_subcate_byurl($url)
    8. {
    9. $rs = strpos($url,"category");
    10. if($rs!==false)
    11. {
    12. preg_match("/\d+/i",$url,$matches);
    13. $cid = $matches[0];
    14. $cat_arr = array();
    15. $sql = "select * from ".$GLOBALS['ecs']->table('category')." where parent_id=".$cid." and is_show=1";
    16. $res = $GLOBALS['db']->getAll($sql);
    17. foreach($res as $idx => $row)
    18. {
    19. $cat_arr[$idx]['id']   = $row['cat_id'];
    20. $cat_arr[$idx]['name'] = $row['cat_name'];
    21. $cat_arr[$idx]['url']  = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
    22. $cat_arr[$idx]['children'] = get_clild_list($row['cat_id']);
    23. }
    24. return $cat_arr;
    25. }
    26. else
    27. {
    28. return false;
    29. }
    30. }
    31. function get_clild_list($pid)
    32. {
    33. //开始获取子分类
    34. $sql_sub = "select * from ".$GLOBALS['ecs']->table('category')." where parent_id=".$pid." and is_show=1";
    35. $subres = $GLOBALS['db']->getAll($sql_sub);
    36. if($subres)
    37. {
    38. foreach ($subres as $sidx => $subrow)
    39. {
    40. $children[$sidx]['id']=$subrow['cat_id'];
    41. $children[$sidx]['name']=$subrow['cat_name'];
    42. $children[$sidx]['url']=build_uri('category', array('cid' => $subrow['cat_id']), $subrow['cat_name']);
    43. }
    44. }
    45. else
    46. {
    47. $children = null;
    48. }
    49. return $children;
    50. }
    51. ?>

ecshop简单三部实现导航分类二级菜单的更多相关文章

  1. Bootstrap系列 -- 40. 导航条二级菜单

    在导航条中添加二级菜单也非常简单 <div class="navbar navbar-default" role="navigation"> < ...

  2. dedecms织梦导航栏二级菜单的实现方法

    dede导航下拉菜单,一级栏目增加二级下拉菜单   使用dedecms5.6——5.7 将这段代码贴到templets\default\head.htm文件里<!-- //二级子类下拉菜单,考虑 ...

  3. PHPCMS v9 导航显示二级菜单,显示相邻栏目,内容页显示二级栏目

    导航显示二级栏目 <div class="menu">{pc:content action="category" catid="0&quo ...

  4. 简单仿京东导航下拉菜单 javascript

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  5. 兼容ie7的导航下拉菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 纯CSS实现二级导航下拉菜单--css的简单应用

    思想:使用css的display属性控制二级下拉菜单的显示与否.当鼠标移动到一级导航菜单的li标签时,显示二级导航菜单的ul标签.由于实现起来比较简单,所以在这里直接给出了参考代码. 1.纯CSS二级 ...

  7. 通用方法解决dedecms导航调用二级、三级栏目菜单

    博客之前做网站的时候经常会遇到二级菜单.三级菜单.了解dede的人都知道从5.5版本开始都有二级菜单的调用方法了,网上也有不少的教程文章.不过这个调用需要修改dede源码的二级菜单样式.个人感觉不是很 ...

  8. JS实现的简单横向伸展二级菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. bootstrap学习笔记之为导航条添加标题、二级菜单及状态 http://www.imooc.com/code/3120

    为导航条添加标题.二级菜单及状态 加入导航条标题 在Web页面制作中,常常在菜单前面都会有一个标题(文字字号比其它文字稍大一些),其实在Bootstrap框架也为大家做了这方面考虑,其通过" ...

随机推荐

  1. Visual Studio 编译纯 C 项目的方法

    项目属性 -> 配置属性 -> C/C++ -> 高级 -> 编译为 -> 选择 `编译为C代码(/TC)` 参考资料: http://stackoverflow.com ...

  2. flock防止重复rsync

    我使用crontab同步一个文件夹时,发现一个问题,我在crontab中设置的1分钟运行一次.但当那个文件夹的内容改变时.1分钟不一定能同步完,但这时第二个rsync进行又起来了. 这个就产生一个问题 ...

  3. 关于django post表单

    CSRF verification failed. Request aborted. 默认会出现该状况,解决办法: 1. 使用requestcontext from django.template i ...

  4. PostgreSQL Replication之第九章 与pgpool一起工作(7)

    9.7 处理故障转移和高可用 可以使用pgpool来解决的一些明显的问题是高可用性和故障转移.一般来讲,有使用pgpool或者不使用pgpool可以用来处理这些问题的各种方法. 9.7.1 使用Pos ...

  5. 暴力枚举-数长方形(hdu5258)

    数长方形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. windows namedPipe 命名管道clent and server

    1.client: #include "iostream" #include "windows.h" using namespace std; void mai ...

  7. JSon_零基础_004_将Set集合对象转换为JSon格式的对象字符串,返回给界面

    将Set集合对象转换为JSon格式的对象字符串,返回给界面 需要导入的jar包: 编写:servlet: package com.west.webcourse.servlet; import java ...

  8. sql字符转换函数大全

    删除空格 有两个函数,TTRIM()和LTRIM(),可以用来从字符串中剪掉空格.函数LTRIM()去除应该字符串前面的所有空格:函数RTRIM()去除一个字符串尾部的所有空格.这些和vbscript ...

  9. sqlhelper-sql数据库

    using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; usin ...

  10. memcached +php环境配置和分析

    一.memcached 简介 在很多场合,我们都会听到 memcached 这个名字,但很多同学只是听过,并没有用过或实际了解过,只知道它是一个很不错的东东.这里简单介绍一下,memcached 是高 ...