Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30285
  • 博文数量: 16
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 150
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-05 09:16
文章分类
文章存档

2011年(1)

2010年(1)

2009年(14)

我的朋友
最近访客

分类: 系统运维

2009-11-17 22:59:54

Dedecms 默认的菜单为一级的(使用dede:channel标签),但是有很多项目需要实现多级菜单.
 
1. 在common.inc.php中定义一个全局变量: $wyq_menu
 
查询表获取菜单结构:
     
  •   
          
    • 子菜单1
    •     
          
    • 子菜单2
    •     
          
    • 子菜单3
    •   
       
       
    •   
            
      • 子菜单1
      •     
            
      • 子菜单2
      •     
            
      • 子菜单3
      •   
         
        样例代码:
         

        global $wyq_menu, $lang1, $news_link, $product_link, $swf_link;

        $news_link = 'list.php?tid=1';
        $product_link = 'list.php?tid=27';
        $lang1 = (isset($tid) && is_numeric($tid) ? $tid : 1);
        $swf_link = 'main.swf';

        if($lang1) {
            $wyq_menu = getMenu($lang1);
        }

        function getMenu($lang1) {
            global $news_link, $product_link, $swf_link;
            $wyq_sql=new DedeSql(false);
            $wyq_sql0=new DedeSql(false);
            //获取语言
            while(1) {
                $inquery = "select * from #@__arctype where id=$lang1 and ishidden!=1";
                $wyq_sql->SetQuery($inquery);
                $wyq_sql->execute();
                if($row0 = $wyq_sql->GetArray()) {
                    if($row0['reid'] != '0') {
                        $lang1 = $row0['reid'];
                        $tmp_ = explode('.swf', $row0['description']);
                        if(count($tmp_) > 1) {
                            $swf_link = $row0['description'];
                        }
                    }
                    else {
                        $typelink1 = GetTypeUrl1($row0['id'],$row0['typedir'],$row0['isdefault'],
                     $row0['defaultname'],$row0['ispart'],$row0['namerule2']);
                        break;
                    }
                }
            }
            
            $inquery = "select * from #@__arctype where reid=$lang1 and ishidden!=1 order by sortrank desc";
            $wyq_sql->SetQuery($inquery);
            $wyq_sql->execute();
            
            $wyq_menu = '

        ';
            return $wyq_menu;
        }

        //栏目目录规则
        function MfTypedir1($typedir)
        {
            if(eregi("^http:",$typedir)) return $typedir;
            $typedir = str_replace("{cmspath}",$GLOBALS['cfg_cmspath'],$typedir);
            $typedir = ereg_replace("/{1,}","/",$typedir);
            return $typedir;
        }
        //获得指定类目的URL链接
        //对于使用封面文件和单独页面的情况,强制使用默认页名称
        function GetTypeUrl1($typeid,$typedir,$isdefault,$defaultname,$ispart,$namerule2)
        {
            $typedir = MfTypedir1($typedir);
            if($isdefault==-1)
            {
                //动态
                $reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid;
            }
            else if($ispart==2)
            {
                //跳转网址
                $reurl = $typedir;
                return $reurl;
            }
            else
            {
                if($isdefault==0 && $ispart==0)
                {
                    $reurl = str_replace("{page}","1",$namerule2);
                    $reurl = str_replace("{tid}",$typeid,$reurl);
                    $reurl = str_replace("{typedir}",$typedir,$reurl);
                } else {
                    $reurl = $typedir.'/'.$defaultname;
                }
            }

            if( !eregi("^http://",$reurl) ) {
                $reurl = ereg_replace("/{1,}",'/',$reurl);
            }
            
            return $reurl;
        }

        2. 在en/header.htm替换{dede:channel}为{dede:global name='wyq_menu'/}

        3. 使用StuHover菜单

        查看: 官方网站更多具体的效果.

        阅读(2807) | 评论(0) | 转发(0) |
        给主人留下些什么吧!~~