• Ecshop中导航栏中使用二级菜单显示并调用子分类


    1:在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;

      }

      2:接下来呢,ecshop中的模板文件,也就是thems,找到你自己的模板文件夹,我就使用默认的说好了,打开themesdefaultlibrarypage_header.lbi文件

      找到ecshop的导航条模板文件代码,也就是以下代码:

      <div id="mainNav" class="clearfix">

      <li><a href="../index.php"{if $navigator_list.config.index eq 1} class="cur"{/if}>{$lang.home}<span></span></a></li>

      <!-- {foreach name=nav_middle_list from=$navigator_list.middle item=nav} -->

      <li><a href="{$nav.url}" {if $nav.opennew eq 1}target="_blank" {/if} {if $nav.active eq 1}class="cur" {/if} >{$nav.name}<span></span></a></li>

      <!-- {/foreach} -->

      </div>

      在代码中加入一段调用分类的代码,位置看你如何构思二级分类的表现,我是直接这样加的,我是直接使用鼠标移到或移出当前栏目名称时,更改当前栏目标签的CLASS名称和CSS样式结合达到二级栏目的显示和隐藏的:

      <div id="mainNav" class="clearfix">

      <li><a href="../index.php"{if $navigator_list.config.index eq 1} class="cur"{/if}>{$lang.home}<span></span></a></li>

      <!-- {foreach name=nav_middle_list from=$navigator_list.middle item=nav} -->

      <li onMouseOver="this.className='menu1'" onMouseOut="this.className='menu2'" class="menu2" id="netxu">

      <a href="{$nav.url}" {if $nav.opennew eq 1}target="_blank" {/if} {if $nav.active eq 1}class="cur" {/if} >{$nav.name}<span></span></a>

      <?php

      $subcates = get_subcate_byurl($GLOBALS['smarty']->_var['nav']['url']);

      if($subcates!=false)

      {

      if(count($subcates)>0)

      {

      if($subcates)

      {

      $i = 1;

      echo "<div class='cnav' id='cnav'>";

      foreach($subcates as $cate)

      {

      if($i % 2 == 0)

      {

      }

      else

      {

      }

      echo "<div class='class_box'>";

      echo "<a class='level_1' href='".$cate['url']."' >".$cate['name']."</a>";

      echo "</p>";

      if($cate['children'])

      {

      foreach($cate['children'] as $subcate)

      {

      echo "<p class='three'>";

      echo "<a href='".$subcate['url']."' class='level_2'>".$subcate['name']."</a>";

      echo "</p>";

      }

      echo "</div>";

      }

      }

      echo "</div>";

      }

      }

      }

      ?>

      </li>

      <!-- {/foreach} -->

      </div>

      3:css样式

      #mainNav { 974px; background:url(images/nav_bg.gif) repeat-x; height:38px; border:1px solid #d1d1d1; line-height:38px; }

      #mainNav li { display:inline; list-style:none; list-style-position:outside; text-align:center; font-weight:bold; float:left; }

      #mainNav li a { color:#614F11; text-decoration:none; display:block; border-right:1px solid #d1d1d1; padding:0 30px; }

      #mainNav .menu1 a{ background:url(images/nav_hover.gif) repeat-x; }

      .menu1 { display:block; }

      .menu1 .cnav { display:block; }

      .cnav { min-350px; max-700px; background:#FFF; z-index:10; position:absolute; display:none; border:3px solid #FFD531; border-top:8px solid #FFD531; text-align:left; padding:10px; }

      #mainNav li .cnav a { font-size:12px; color:#333333; padding:0; text-align:left; margin-left:5px; font-size:12px; border:none; height:30px; line-height:30px; border-bottom:1px solid #ccc; background:none;}

      #mainNav li .cnav a:hover { background:none; text-decoration:underline; color:#FFA500; }

      #mainNav li .cnav p { display:inline; }

      #mainNav li .cnav .three a { font-weight:normal; border:none; height:15px; line-height:15px; margin-top:8px; }

  • 相关阅读:
    php pcntl 多进程学习
    php socket 学习
    linux 常用alias
    php 设置一个函数的最大运行时间
    QTableView 一列添加两个按钮
    翻译qmake文档 目录
    翻译qmake文档(四) Building Common Project Types
    算法时间复杂度
    翻译qmake文档(三) Creating Project Files
    Caliburn.Micro学习笔记目录
  • 原文地址:https://www.cnblogs.com/jevil/p/3144283.html
Copyright © 2020-2023  润新知