Skip to content

Instantly share code, notes, and snippets.

@JonasDoebertin
Last active December 30, 2015 19:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JonasDoebertin/7874344 to your computer and use it in GitHub Desktop.
Save JonasDoebertin/7874344 to your computer and use it in GitHub Desktop.
XML Sitemap for Kirby CMS

sitemap.xml for Kirby CMS

Notes:

  • Remember to exclude the sitemap from caching, search and the sitemap itself!
<?php
/* Specify pages that will be excluded from the sitemap */
c::set('custom.sitemap.ignore', array('sitemap', 'suche', 'team/[...]'));
<?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