Sayfalar

25 Mayıs 2016 Çarşamba

Php Create sitemap

  1. // begin xml content
  2. $XML_Content = '<urlset xmlns:xsi=
  3. "http://www.w3.org/2001/XMLSchema-instance" 
  4. xsi:schemaLocation="http://www.fem14.tr.gg/schemas/sitemap/0.9 '."\\n".
  5. 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" 
  6. xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\\n";
  7. foreach ($urllist as $url){ // $urllist= your website urls
  8.     // defaults
  9.     $date = date('Y-m-d');
  10.     $freq = 'monthly';
  11.     $priority = '0.5';
  12.     // setting values
  13.     if( is_array($url) ){
  14.         // custom params
  15.         if( $url[date] ) $date = $url[date];
  16.         if( $url[freq] ) $freq = $url[freq];
  17.         if( $url[priority] ) $priority = $url[priority];
  18.         $url = $url[url];
  19.     }else{
  20.         $url = $url;
  21.     }
  22.     // adding to xml content
  23.     $XML_Content .= "\\t<url>\\n".
  24.     "\\t\\t<loc>$url</loc>\\n".
  25.     "\\t\\t<lastmod>$date</lastmod>\\n".
  26.     "\\t\\t<changefreq>$freq</changefreq>\\n".
  27.     "\\t\\t<priority>$priority</priority>\\n".
  28.     "\\t</url>\n";
  29. }
  30. $XML_Content .= "</urlset>";

  31. $file = fopen('sitemap.xml', 'w') )
  32. fwrite($file, $XML_Content);
  33. fclose($file);


sitemap.xml(output)
  1. <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  2. xsi:schemaLocation="http://www.fem14.tr.gg/schemas/sitemap/0.9
  3. http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" 
  4. xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  5.     <url>
  6.         <loc>http://www.yourdomainname.com/adres1</loc>
  7.         <lastmod>2007-10-10</lastmod>
  8.         <changefreq>daily</changefreq>
  9.         <priority>0.9</priority>
  10.     </url>
  11.     <url>
  12.         <loc>http://www.yourdomainnam.com/adres2</loc>
  13.         <lastmod>2007-10-10</lastmod>
  14.         <changefreq>monthly</changefreq>
  15.         <priority>0.5</priority>
  16.     </url>
  17. </urlset>

Hiç yorum yok:

Yorum Gönder