index-shop/site/snippets/sitemap.php

55 lines
1.6 KiB
PHP
Raw Normal View History

<?= '<?xml version="1.0" encoding="UTF-8"?>' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<?php
$site = site();
$kirby = kirby();
// Static pages
$pages = $site->index()->filterBy('template', 'in', ['home', 'error', 'thanks']);
foreach ($pages as $p) {
foreach ($kirby->languages() as $lang) {
$url = $p->url($lang->code());
?>
<url>
<loc><?= $url ?></loc>
<lastmod><?= $p->modified('c', 'date') ?></lastmod>
<changefreq>monthly</changefreq>
<priority><?= $p->isHomePage() ? '1.0' : '0.8' ?></priority>
<?php foreach ($kirby->languages() as $altLang): ?>
<xhtml:link rel="alternate" hreflang="<?= $altLang->code() ?>" href="<?= $p->url($altLang->code()) ?>" />
<?php endforeach ?>
</url>
<?php
}
}
// Virtual product pages from Shopify
$products = getShopifyProducts();
foreach ($products as $product) {
foreach ($kirby->languages() as $lang) {
$url = $lang->code() == 'fr'
? $site->url() . '/' . $product['handle']
: $site->url() . '/en/' . $product['handle'];
?>
<url>
<loc><?= $url ?></loc>
<lastmod><?= date('c') ?></lastmod>
<changefreq>weekly</changefreq>
<priority>0.9</priority>
<?php foreach ($kirby->languages() as $altLang): ?>
<?php
$altUrl = $altLang->code() == 'fr'
? $site->url() . '/' . $product['handle']
: $site->url() . '/en/' . $product['handle'];
?>
<xhtml:link rel="alternate" hreflang="<?= $altLang->code() ?>" href="<?= $altUrl ?>" />
<?php endforeach ?>
</url>
<?php
}
}
?>
</urlset>