- Remember to exclude the sitemap from caching, search and the sitemap itself!
Last active
December 30, 2015 19:29
-
-
Save JonasDoebertin/7874344 to your computer and use it in GitHub Desktop.
XML Sitemap for Kirby CMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Specify pages that will be excluded from the sitemap */ | |
c::set('custom.sitemap.ignore', array('sitemap', 'suche', 'team/[...]')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Set correct header */ | |
header('Content-type: text/xml; charset="utf-8"'); | |
/* Echo the doctype */ | |
echo '<?xml version="1.0" encoding="utf-8"?>'; | |
/* Get ignored files from config file */ | |
$ignore = c::get('custom.sitemap.ignore', array()); | |
?> | |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | |
<?php foreach( $pages->index() as $page ): ?> | |
<?php /* Skip loop for ignored pages */ ?> | |
<?php if( in_array($page->uri(), $ignore) ) continue; ?> | |
<url> | |
<loc><?= html($page->url()) ?></loc> | |
<lastmod><?= $page->modified('c') ?></lastmod> | |
<priority><?= ($page->isHomePage()) ? 1 : number_format(0.5/$page->depth(), 1) ?></priority> | |
</url> | |
<?php endforeach ?> | |
</urlset> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment