PDO::ERRMODE_EXCEPTION] ); } catch (Exception $e) { die("Database bağlantı hatası"); } $urls = []; /* ----------------- STATİK SAYFALAR -------------------*/ $urls[] = [ "loc" => "$baseUrl/", "priority" => "1.0", "changefreq" => "daily" ]; $staticPages = ["hakkimizda","iletisim","arac-kiralama","blog"]; foreach ($staticPages as $page) { $urls[] = [ "loc" => "$baseUrl/$page", "priority" => "0.9", "changefreq" => "weekly" ]; } /* ----------------- BLOG YAZILARI tablo: posts kolon: slug, updated_at, status -------------------*/ $stmt = $pdo->query("SELECT slug, updated_at FROM posts WHERE status='published'"); foreach ($stmt as $row) { $urls[] = [ "loc" => "$baseUrl/blog/" . $row['slug'], "lastmod" => date('Y-m-d', strtotime($row['updated_at'])), "priority" => "0.7", "changefreq" => "monthly" ]; } /* ----------------- ARAÇLAR tablo: cars kolon: slug, updated_at, is_active -------------------*/ $stmt2 = $pdo->query("SELECT slug, updated_at FROM cars WHERE is_active=1"); foreach ($stmt2 as $row) { $urls[] = [ "loc" => "$baseUrl/araclar/" . $row['slug'], "lastmod" => date('Y-m-d', strtotime($row['updated_at'])), "priority" => "0.8", "changefreq" => "weekly" ]; } /* ----------------- XML OLUŞTUR -------------------*/ $xml = "\n"; $xml .= "\n"; foreach ($urls as $url) { $xml .= " \n"; $xml .= " {$url['loc']}\n"; if (!empty($url['lastmod'])) { $xml .= " {$url['lastmod']}\n"; } $xml .= " {$url['changefreq']}\n"; $xml .= " {$url['priority']}\n"; $xml .= " \n"; } $xml .= ""; file_put_contents($cacheFile, $xml); echo $xml;