Exclude children of a page from sitemap.xml?

Hi People!

I took the official advice from the kirby blog to set a page where I can output a sitemap.xml file.

But the sitemap also shows the children of a page, e.g. the articles of my news page (“aktuelles”).

<?php
header('Content-type: text/xml; charset="utf-8"');
echo '<?xml version="1.0" encoding="utf-8"?>';
$ignore = array('sitemap', 'error', 'impressum', 'datenschutz', 'aktuelles');
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <?php foreach($pages->index()->visible() as $p): ?>
    <?php if(in_array($p->uri(), $ignore)) continue ?>
  <url>
    <loc><?php echo html($p->url()) ?></loc>
    <lastmod><?php echo $p->modified('c') ?></lastmod>
    <priority><?php echo ($p->isHomePage()) ? 1 : number_format(0.5/$p->depth(), 1) ?></priority>
  </url>
  <?php endforeach ?>
</urlset>

Anyone has a clue to fade out those children?

This doesn’t work:

<?php if(in_array($p->children(), $ignore)) continue ?>

Thanks in advance for your help!

Try this:

<?php if(in_array($p->uri(), $ignore) || in_array($p->parent()->uri(), $ignore)) continue ?>

Works perfectly. Thank you Sonja! :slight_smile: