<!--#include file="dbbaglanti.asp"-->
<%
Function Urlekle(url,tarih,oncelik,guncellenme)
etiket="<url>"&chr(10)&chr(13)&" <loc>"&url&"</loc>"
if tarih<>"" then
etiket=etiket&chr(10)&chr(13)&" <lastmod>"&tarih&"</lastmod>"
end if
etiket=etiket&chr(10)&chr(13)&" <changefreq>"&guncellenme&"</changefreq>"
etiket=etiket&chr(10)&chr(13)&" <priority>"&oncelik&"</priority>"&chr(10)&chr(13)&" </url>"
Urlekle=etiket
End Function
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
FSO.createTextFile Server.Mappath("sitemap.xml")
set harita = FSO.openTextFile(Server.MapPath("sitemap.xml"),2,0)
haritaveri=Urlekle("http://www.siteadi.com","","1.0","hourly")
do while not rs.eof
urlmiz = "http://www.siteadi.com/dosya.asp?dosya_id="&rs("id")
tarih=year(rs("tarih"))&"-"&right("0"&month(rs("tarih")),2)&"-"&right("0"&day(rs("tarih")),2)
haritaveri=haritaveri&chr(10)&chr(13)&chr(10)&chr(13)&Urlekle(urlmiz,""&tarih&"","0.5","weekly")
rs.movenext
loop
rs.close
set rs = nothing
veri="<?xml version=""1.0"" encoding=""UTF-8""?>"
veri=veri&"<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">"
haritaveri=veri&haritaveri&"</urlset>"
harita.write(haritaveri)
harita.close
set harita = nothing
set FSO = nothing
response.write "Sitemap dosyanız oluşturulmuştur.Oluşturulan sitemap dosyanızı görüntülemek için <a href="sitemap.xml">buraya</a> tıklayın."
%>Sitem için bu mantıkta bir kod yazdım gayet güzel çalışıyor. Db den kayıtları çekip "sitemap.xml" dosyasına yazdırıyor. İçeriğinizi güncelledikçe girip bir kere bu dosyayı çalıştırın sitemap.xml dosyanız güncellenir.
Eğer google her geldiğinde sitemapın güncellenmesini istiyorsanız: yukarıdaki kodlardan şu kodları çıkarıp :
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
FSO.createTextFile Server.Mappath("sitemap.xml")
set harita = FSO.openTextFile(Server.MapPath("sitemap.xml"),2,0)Bu bölümü de:
veri="<?xml version=""1.0"" encoding=""UTF-8""?>"
veri=veri&"<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">"
haritaveri=veri&haritaveri&"</urlset>"
harita.write(haritaveri)
harita.close
set harita = nothing
set FSO = nothing
Aşağıdaki gibi değiştirin.
veri="<?xml version=""1.0"" encoding=""UTF-8""?>"
veri=veri&"<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">"
haritaveri=veri&haritaveri&"</urlset>"
response.write haritaveri
harita.close
set harita = nothing
set FSO = nothing
Veri tabanı + FSO + do while döngüsü ile sitemapımızı oluşturduk.
Zamanım az olmasa satır satır açıklardım. Şimdilik bunla idare edin