动态管理导航条
作者:齐人无福
来源:
ITPOW
日期:2002-8-3
-----------------------
作者:齐人无福
主页:www.nettun.com
几乎每个网站都有导航条,但页面多了,导航条就难以管理,如果要更改导航条,那么
就得
更改许多的页面。为了解决这个问题,有一种做法就是利用包含文件,这其中需要解决的一
个问
题就是指向当前页面的链接不需要显示。下面用到了数据库,其实可以用数组代替的,用数
据库
的目的是为了在线管理方便。
================navigator.asp
<%
dim cnNav,rsNav,sqlNav
set cnNav=Server.CreateObject("ADODB.Connection")
cnNav.open "provider=microsoft.jet.oledb.4.0;data source="&Server.MapPath
(modifyPath&"*******.mdb")
set rsNav=Server.CreateObject("ADODB.RecordSet")
sqlNav="select * from navigation"
%>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:
collapse" width="760" height="19">
<tr>
<%
rsNav.open sqlNav,cnNav,1,1
dim iNav,NavCount,categoryDepth,linkLen,linkURL,jNav,titleWidth
NavCount=rsNav.recordCount
if thisNav>NavCount-1 then thisNav=NavCount-1
rsNav.move thisNav
linkURL=rsNav("linkURL")
linkLen=len(linkURL)
for jNav=1 to linkLen
if mid(linkURL,jNav,1)="/" then categoryDepth=categoryDepth+1
next/////////取得目录深度
rsNav.moveFirst
iNav=0
titleWidth=760/rsNav.recordCount
do while not rsNav.eof
linkURL=rsNav("linkURL")
for jNav=1 to categoryDepth
linkURL="../"+linkURL
next////////获取正确的路径
if iNav=thisNav then
response.write("<td width="&titleWidth&" height=19 align=center
bgcolor="&titleBgColor&"><a class=title>"&rsNav("title")&"</a></td>")
else
response.write("<td width="&titleWidth&" height=19 align=center
bgcolor="&titleBgColor&"><a href="&linkURL&" class=title>"&rsNav("title")
&"</a></td>")
end if
iNav=iNav+1
rsNav.moveNext
loop
%>
</tr>
</table>
</center>
</div>
<%
rsNav.close
set rsNav=nothing
cnNav.close
set cnNav=nothing
%>
=======================引用
<%
dim thisNav,modifyPath,titleBgColor
thisNav=0//当前页面对应的菜单
modifyPath=""//为解决路径而设。
titleBgColor="#FFD900"//导航条背景色
%>
<!--#include file="navigator.asp"-->
=======================