zoukankan      html  css  js  c++  java
  • ecshop简单三部实现导航分类二级菜单

     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}><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.                    <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.                                  
    18.                                 if($subcates) 
    19.                                 { 
    20.                                 foreach($subcates as $cate) 
    21.                                 { 
    22.                                         echo "<href='".$cate['url']."' class='level_1'>".$cate['name']."</a>"; 
    23.                                     
    24.                                 } 
    25.                                 }                                 
    26.                                 echo "</div><iframe frameborder='0' scrolling='no' class='nomask'></iframe>"; 
    27.                             } 
    28.                         } 
    29.                              ?> 
    30.                    </li
    31.                  <!-- {/foreach} --> 
    32.             </ul
    33.       <script type="text/javascript"
    34.       //初始化主菜单 
    35.                 function sw_nav(obj,tag) 
    36.                 { 
    37.  
    38.                         var subdivs = obj.getElementsByTagName("DIV"); 
    39.                         var ifs = obj.getElementsByTagName("IFRAME"); 
    40.                          
    41.                         if(subdivs.length>0) 
    42.                         { 
    43.  
    44.                                 if(tag==1) 
    45.                                 { 
    46.                                         subdivs[0].style.display = "block"; 
    47.                                         ifs[0].style.display = "block"; 
    48.                                 } 
    49.                                 else 
    50.                                 { 
    51.                                         subdivs[0].style.display = "none";         
    52.                                         ifs[0].style.display = "none"; 
    53.                                 } 
    54.                                  
    55.                         } 
    56.                 } 
    57.  
    58.       </script>  
    59. </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.  
    8. .sub_nav{ background:#999;110px; position:absolute; z-index:5003; display:none;margin-left:-12px;} 
    9. .nomask{ background:#fff; 110px; height:50px; position:absolute; z-index:5002;display:none;margin-left:-12px;} 
    10. .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;} 
    11. .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.     $rs = strpos($url,"category"); 
      9.     if($rs!==false) 
      10.     { 
      11.         preg_match("/d+/i",$url,$matches); 
      12.         $cid = $matches[0]; 
      13.         $cat_arr = array(); 
      14.         $sql = "select * from ".$GLOBALS['ecs']->table('category')." where parent_id=".$cid." and is_show=1"; 
      15.         $res = $GLOBALS['db']->getAll($sql); 
      16.          
      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.  
      25.         return $cat_arr; 
      26.     } 
      27.     else  
      28.     { 
      29.         return false; 
      30.     } 
      31.  
      32. function get_clild_list($pid) 
      33.    //开始获取子分类 
      34.     $sql_sub = "select * from ".$GLOBALS['ecs']->table('category')." where parent_id=".$pid." and is_show=1"; 
      35.  
      36.     $subres = $GLOBALS['db']->getAll($sql_sub); 
      37.     if($subres) 
      38.     { 
      39.         foreach ($subres as $sidx => $subrow) 
      40.         { 
      41.             $children[$sidx]['id']=$subrow['cat_id']; 
      42.             $children[$sidx]['name']=$subrow['cat_name']; 
      43.             $children[$sidx]['url']=build_uri('category', array('cid' => $subrow['cat_id']), $subrow['cat_name']); 
      44.         } 
      45.     } 
      46.     else  
      47.     { 
      48.         $children = null; 
      49.     } 
      50.              
      51.     return $children; 
      52.  
      53. ?> 
  • 相关阅读:
    Linux各主要发行版的包管理命令对照
    JDK 生成数字证书
    AbatorForEclipse插件使用总结
    [转载]在rhel 6 x86_64 上安装oracle 11g xe
    【转载】PL/SQL配置连接ORACLE
    Archlive新年第一棒: 基于2.6.37稳定内核的archlive20110107
    基于Arch的live系统
    【转】MyEclipse 9.0正式版官网下载(附Win+Llinux激活方法、汉化包)
    Exception in thread main java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFacto
    MyEclipse 8.6插件下载
  • 原文地址:https://www.cnblogs.com/GmrBrian/p/4170692.html
Copyright © 2011-2022 走看看