-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitemap.php
82 lines (75 loc) · 2.57 KB
/
sitemap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
require './app/init.php'; // Veritabanı bağlantısını alıyoruz.
header("Content-Type: application/xml; charset=UTF-8");
ob_start();
// URL'leri toplamak için diziyi başlatıyoruz
$urls = [];
$urls[] = [
'loc' => 'https://YOUR_URL.com',
'priority' => '1.0',
'changefreq' => 'daily',
];
$urls[] = [
'loc' => 'https://YOUR_URL.com/about-us',
'priority' => '1.0',
'changefreq' => 'daily',
];
$urls[] = [
'loc' => 'https://YOUR_URL.com/contact',
'priority' => '1.0',
'changefreq' => 'daily',
];
$urls[] = [
'loc' => 'https://YOUR_URL.com/category',
'priority' => '1.0',
'changefreq' => 'daily',
];$urls[] = [
'loc' => 'https://YOUR_URL.com/products',
'priority' => '1.0',
'changefreq' => 'daily',
];
// Kategorilerden URL'leri almak (ID'leri kullanarak)
$categories = $db->query("SELECT id, updated_at FROM categories")->fetchAll(PDO::FETCH_ASSOC);
foreach ($categories as $category) {
$urls[] = [
'loc' => 'https://YOUR_URL.com/category/' . $category['id'], // ID ile URL oluşturuyoruz
'priority' => '0.8',
'changefreq' => 'weekly',
'lastmod' => date(DATE_W3C, strtotime($category['updated_at'])),
];
}
// Ürünlerden URL'leri almak (ID'leri kullanarak)
$products = $db->query("SELECT id, updated_at FROM products")->fetchAll(PDO::FETCH_ASSOC);
foreach ($products as $product) {
$urls[] = [
'loc' => 'https://YOUR_URL.com/product-detail/' . $product['id'], // ID ile URL oluşturuyoruz
'priority' => '0.7',
'changefreq' => 'weekly',
'lastmod' => date(DATE_W3C, strtotime($product['updated_at'])),
];
}
// Pörtföylerden URL'leri almak (ID'leri kullanarak)
$products = $db->query("SELECT id, updated_at FROM portfolios")->fetchAll(PDO::FETCH_ASSOC);
foreach ($products as $product) {
$urls[] = [
'loc' => 'https://YOUR_URL.com/portfolio/' . $product['id'], // ID ile URL oluşturuyoruz
'priority' => '0.7',
'changefreq' => 'weekly',
'lastmod' => date(DATE_W3C, strtotime($product['updated_at'])),
];
}
// XML çıktısını oluşturma
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">';
foreach ($urls as $url) {
echo '<url>';
echo '<loc>' . htmlspecialchars($url['loc']) . '</loc>';
if (isset($url['lastmod'])) {
echo '<lastmod>' . $url['lastmod'] . '</lastmod>';
}
echo '<changefreq>' . $url['changefreq'] . '</changefreq>';
echo '<priority>' . $url['priority'] . '</priority>';
echo '</url>';
}
echo '</urlset>';
ob_end_flush();