And then a specially tailored for Google sitemap to generate code, (but dynamic OH) _ Application Techniques

Source: Internet
Author: User
Tags servervariables
See friends can help top oh, these codes are the first hair, outside a lot of it is very complicated, do not understand, or can not be used, the following I write time has been as concise as possible
Outside a lot of so-called Sitemap generation code only generates directory file address, not generated dynamic, I later wrote this, is to support dynamic, examples:
If you are the article site, the article has 2000, then you modify the corresponding article data table, you can generate in addition to all catalog files, but also generate your dynamic 2000 address, absolutely no words, the production speed is very fast
Save the following code as a sitemap.asp file, modify some of the places I have indicated, do not change the rest, do not know how to use it
Copy Code code as follows:
<!--#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") &am P "-->"
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 [table name to generate] ORDER by SID ASC"///Modify the name of the datasheet you want to generate
Set js = Conn.execute (SQL)
Do Until js.eof
Id= "" &js ("id") & ""///modify to your ID field
Foolcat = Foolcat + "<url>"
Foolcat = Foolcat + "<loc>" & strURL & "/xxx.asp?" Id= "& ID &" </loc> "//modified for your file name and ID
Foolcat = Foolcat + "</url>"
Session ("Count") =session ("Count") + "1"
Js.movenext
Loop
Js.close
Set js = Nothing
Foolcat = Foolcat + "</urlset>"
Foolcat = "" + Foolcat + ""
Foolcat = "" & Foolcat & ""
FolderPath = Server.MapPath ("/")
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
Set fout = fso. CreateTextFile (folderpath& "\sitemap.xml")
Fout.writeline Foolcat
Fout.close
Set fout = Nothing
Conn.close
Set conn = Nothing
Function return_rfc822_date (ByVal mydate, ByVal TimeZone)
Dim Myday, Mydays, Mymonth, myyear
Dim myhours, Myminutes, Myseconds

MyDate = CDate (mydate)
Myday = Enweekdayname (mydate)
Mydays = Right ("A" & Day (MyDate), 2)
Mymonth = Enmonthname (mydate)
Myyear = year (mydate)
Myhours = Right ("& Hour" (MyDate), 2)
Myminutes = Right ("& Minute" (MyDate), 2)
Myseconds = Right ("& Second" (MyDate), 2)

Return_rfc822_date = myday& "," & _
mydays& "" & _
mymonth& "" & _
myyear& "" & _
myhours& ":" & _
myminutes& ":" & _
myseconds& "" & _
"" & TimeZone
End Function
Function Enweekdayname (inputdate)
Dim result
Select case Weekday (inputdate,1)
Case 1:result= "Sun"
Case 2:result= "Mon"
Case 3:result= "Tue"
Case 4:result= "Wed"
Case 5:result= "Thu"
Case 6:result= "Fri"
Case 7:result= "Sat"
End Select
Enweekdayname = result
End Function
Function Enmonthname (inputdate)
Dim result
Select case Month (inputdate)
Case 1:result= "the"
Case 2:result= "Feb"
Case 3:result= "Mar"
Case 4:result= "APR"
Case 5:result= ' may '
Case 6:result= "June"
Case 7:result= "June"
Case 8:result= "Aug"
Case 9:result= "Sep"
Case 10:result= "OCT"
Case 11:result= "Nov"
Case 12:result= "Dec"
End Select
Enmonthname = result
End Function
%>

Sitemap.xml generated, a total of <%=session ("Count")%> files, click to view <a href= "Sitemap.xml" >sitemap.xml</a> files.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.