43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
header('Content-Type: text/xml');
|
|
// https://www.sitemaps.org/protocol.html
|
|
// Check it here: https://www.mysitemapgenerator.com/service/check.html
|
|
|
|
$query=<<<EOSQL
|
|
SELECT draft, slug, updated, changefreq, priority, path
|
|
FROM pages
|
|
WHERE priority > 0
|
|
AND draft = 0
|
|
ORDER BY updated DESC;
|
|
EOSQL;
|
|
$thepages = $db->getRows($query);
|
|
|
|
// Start the view
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>';
|
|
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
|
|
|
// Loop through the pages
|
|
if ( ! empty($thepages) ) {
|
|
foreach( $thepages as $v) {
|
|
|
|
$date = (new \DateTime($v['updated']))->format('Y-m-d');
|
|
|
|
echo "<url>";
|
|
|
|
if ( empty($v['path']) )
|
|
echo "<loc>" . $config['base_url'] . '/page/' . $v['slug'] . "</loc>";
|
|
else
|
|
echo "<loc>" . $config['base_url'] . $v['path'] . "</loc>";
|
|
|
|
echo "<lastmod>" . $date . "</lastmod>";
|
|
echo "<changefreq>" . $v['changefreq'] . "</changefreq>";
|
|
echo "<priority>" . sprintf("%.1f", $v['priority']) . "</priority>";
|
|
echo "</url>";
|
|
|
|
}
|
|
} else {
|
|
echo "no pages added yet";
|
|
}
|
|
|
|
echo "</urlset>";
|