<!--下拉選單 -->
<{php}>
  global $xoopsDB,$xoopsTpl;
  $sql = "select `menu_sn`  from ".$xoopsDB->prefix('ugm_page_menu')." where `menu_type`='4' and `menu_enable`='1' and `menu_ofsn`='0' order by `menu_sort` limit 1 ";//die($sql);
  $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, web_error());
  list($menu_sn)=$xoopsDB->fetchRow($result);
  if($menu_sn){
    $main= get_ugm_page_tpl_theme_menu_body($menu_sn);
    //print_r($main);die();
    $xoopsTpl->assign('ugm_page_menu',$main);
    // $xoopsTpl->assign('ugm_page_menu_ofsn',$menu_sn);
  }
function get_ugm_page_tpl_theme_menu_body($menu_ofsn=0,$level=0){
  global $xoopsDB;
  $sql = "select *
          from ".$xoopsDB->prefix('ugm_page_menu')."
          where `menu_type`='4' and `menu_enable`='1' and `menu_ofsn`='{$menu_ofsn}'
          order by `menu_sort` ";//die($sql);
  $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, web_error());
  $total=$xoopsDB->getRowsNum($result); #記錄筆數
  if($total==0)return;

  while($all=$xoopsDB->fetchArray($result)){
  //以下會產生這些變數：  `menu_sn`, `menu_type`, `menu_ofsn`, `menu_sort`, `menu_title`, `menu_op`, `menu_tip`, `menu_enable`, `menu_new`, `menu_url`, `menu_date`, `menu_uid`
    foreach($all as $k=>$v){
      $$k=$v;
    }
    if($level==0){
      $sub2=get_ugm_page_tpl_theme_menu_body($menu_sn,1);
      $menu_new=$menu_new?" target='_blank'":"";
      if($sub2){
        # ----有第2層 ----
        $main.="<li  class='dropdown'><a class='dropdown-toggle' data-toggle='dropdown' href='{$menu_url}'{$menu_new}>{$menu_title} <b class='caret'></b></a><ul class='dropdown-menu'>".$sub2;
      }else{
        # ---- 只有第1層 ----
        $main.="<li><a href='{$menu_url}'{$menu_new}>{$menu_title}</a></li>";
      }
    }elseif($level==1){
      $sub3=get_ugm_page_tpl_theme_menu_body($menu_sn,2);
      $menu_new=$menu_new?" target='_blank'":"";
      if($sub3){
        # ----有第3層 ----
        $main.="<li class='dropdown-submenu'><a href='{$menu_url}'{$menu_new}>{$menu_title}</a><ul class='dropdown-menu'>".$sub3;
      }else{
        # ---- 只有第2層 ----
        $main.="<li><a href='{$menu_url}'{$menu_new}>{$menu_title}</a></li>";
      }
    }elseif($level==2){
      $main.="<li><a href='{$menu_url}'{$menu_new}>{$menu_title}</a></li>";
    }
    if(($level==0 and $sub2) or ($level==1 and $sub3)){
      $main.="</ul></li>";
    }
  }
  return $main;
}

<{/php}>
<!--下拉選單 end-->
<style>
  .globalnav{
  	position:relative;
  }
  .searchform{
  	position:absolute;
  	top:5px;
  	right:0;
  }
</style> 
<nav class='navbar navbar-inner globalnav'>
   <div id='nav-collapse' class='nav-collapse collapse'>
      <ul class='nav'>
        <a class='brand' href='<{$xoops_url}>'><{$xoops_sitename}></a>
        <!-- 下拉選單程式開始 -->
        <{$ugm_page_menu}>
        <!-- 下拉選單結束 -->
      </ul>
      <div class="input-append searchform">
      	<form action="<{$xoops_url}>/search.php" method="get">
      		<input class="span2" type="text" name="query" placeholder="Search..." id="search" />
      		<input type="hidden" name="action" value="results" />
      		<button class="btn" type="submit">Go!</button>
      	</form>
      </div>
   </div><!--/.nav-collapse -->
</nav>