Generate code asp for sitemap customized by google

Source: Internet
Author: User

Many so-called code generated by sitemap only generate directory file addresses and do not generate dynamic ones. I wrote this one myself and it supports dynamic ones. For example, if you are an article website, there are 2000 articles, so you can modify the corresponding data table of your article to generate your dynamic 2000 addresses in addition to all directory files, fast generation

Save the following code as the sitemap. asp file and modify the items I have noted. Do not modify any other items. You will only know if they are easy to use.Copy codeThe Code is 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 ") &" -->"
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 [name of the table to be generated] order by id asc" // modify the name of the data table to be generated
Set js = conn.exe cute (SQL)
Do until js. eof

Id = "" & js ("id") "// modify your id field

Foolcat = foolcat + "<url>"
Foolcat = foolcat + "<loc>" & strURL & "/xxx. asp? Id = "& id &" </loc> "// modify 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 ("00" & Day (myDate), 2)
MyMonth = EnMonthName (myDate)
MyYear = Year (myDate)
MyHours = Right ("00" & Hour (myDate), 2)
MyMinutes = Right ("00" & Minute (myDate), 2)
MySeconds = Right ("00" & 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 = "Jan"
Case 2: Result = "Feb"
Case 3: Result = "Mar"
Case 4: Result = "Apr"
Case 5: Result = "May"
Case 6: Result = "Jun"
Case 7: Result = "Jul"
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
%>

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.