11bits
November 28, 2017, 12:33pm
1
Hi,
I omit the blog folder in the URL using routes:
https://getkirby.com/docs/developer-guide/advanced/routing#omitting-the-blog-folder-in-urls
And I have a sitemap with this code:
<?php
$ignore = array('error');
// Send the right header
header('Content-type: text/xml; charset="utf-8"');
// Echo the doctype
echo '<?xml version="1.0" encoding="utf-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach($pages->index()->visible()->not($ignore) as $p): ?>
<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>
I’d like to remove the blog folder in the sitemap URLs and I tried this approach:
The page model (not page method!) would look like this:
<?php
class ArticlePage extends Page {
function url() {
return url($this->uid());
}
}
It works fine, but I wonder if that’s the simplest way to do it or if it’s posible to omit that folder changing the sitemap code and without using models.
I use the Sitemap plugin , which offers much greater control.
texnixe
November 28, 2017, 12:51pm
3
A model is the easiest way to achieve that, because you can overwrite the native url()
method and don’t have to change the code in other contexts of your site. Otherwise, you would need some sort of if statement in your sitemap code.
texnixe
November 28, 2017, 12:52pm
4
@jimbobrjames Could you please explain how that plugin solves the problems with the modified URL?
Ah… perhaps i misunderstood… i got that @11bits simply wanted to exclude some pages from the sitemap.
11bits
November 28, 2017, 12:59pm
6
Yes, I know this plugin and it’s great, but I think it hasn’t this option.
texnixe
November 28, 2017, 1:00pm
7
No, and such a feature wouldn’t make much sense and only bloat the code.
Why don’t you want to use the page model? Do you want to remove the blog template?
11bits
November 28, 2017, 1:06pm
8
Ok, I’ll continue using models.
Danke @texnixe