外面很多所谓sitemap生成代码都只生成目录文件地址,没生成动态的,我后来自己写了这个,是支持动态的,例子:
如你是文章网站,文章有2000条,那你修改下对应你的文章数据表,即可生成除了所有目录文件外,还生成你的动态2000条地址,绝对的没话说,生成速度非常快
把下面代码保存为sitemap.asp文件,修改我已注明的几个地方,其他的一概不要修改,好不好用过才知道
复制代码 代码如下:
<!--#include file="conn.asp"-->
<%
session("count")=0
strURL = "http://" & request.servervariables("SERVER_NAME") & _
left(request.servervariables("SCRIPT_NAME"),len(request.servervariables("SCRIPT_NAME"))-len("/sitemap.asp"))
dim foolcat
foolcat = foolcat + "<?xml version=""1.0"" encoding=""UTF-8""?>"
foolcat = foolcat + "<!--Google Site Map File Generated by http://www.xxx.com " & return_RFC822_Date(now,"GMT") & "-->"
foolcat = foolcat + "<urlset xmlns=""http://www.google.com/schemas/sitemap/0.84"">"
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strURL & "/</loc> "
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
set all_fs = Server.CreateObject("Scripting.FileSystemObject")
set all_folder = all_fs.GetFolder(server.MapPath("/"))
set all_files = all_folder.files
for each file in all_files
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strURL & "/" & File.Name & "</loc> "
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
next
dim js,sql
set js = server.CreateObject("ADODB.RecordSet")
sql = "select * from [要生成的表名] order by sid asc" //修改你要生成的数据表名
set js = conn.execute (sql)
do until js.eof
id=""&js("id")&"" //修改为你的id字段
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strURL & "/xxx.asp?Id=" & id & "</loc> " //修改为你的文件名称和id
<%
session("count")=0
strURL = "http://" & request.servervariables("SERVER_NAME") & _
left(request.servervariables("SCRIPT_NAME"),len(request.servervariables("SCRIPT_NAME"))-len("/sitemap.asp"))
dim foolcat
foolcat = foolcat + "<?xml version=""1.0"" encoding=""UTF-8""?>"
foolcat = foolcat + "<!--Google Site Map File Generated by http://www.xxx.com " & return_RFC822_Date(now,"GMT") & "-->"
foolcat = foolcat + "<urlset xmlns=""http://www.google.com/schemas/sitemap/0.84"">"
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strURL & "/</loc> "
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
set all_fs = Server.CreateObject("Scripting.FileSystemObject")
set all_folder = all_fs.GetFolder(server.MapPath("/"))
set all_files = all_folder.files
for each file in all_files
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strURL & "/" & File.Name & "</loc> "
foolcat = foolcat + "</url>"
session("count")=session("count")+"1"
next
dim js,sql
set js = server.CreateObject("ADODB.RecordSet")
sql = "select * from [要生成的表名] order by sid asc" //修改你要生成的数据表名
set js = conn.execute (sql)
do until js.eof
id=""&js("id")&"" //修改为你的id字段
foolcat = foolcat + "<url>"
foolcat = foolcat + "<loc>" & strURL & "/xxx.asp?Id=" & id & "</loc> " //修改为你的文件名称和id
内容版权声明:除非注明,否则皆为本站原创文章。