Forum

Thread tagged as: Question, Problem, Blog

Sitemap for Blog

Is there anyway to create a sitemap template for blog posts? I was able to follow the article that discusses how to set up the template for a navigation sitemap. It works great, however it doesn't include blog posts.

Nick Santini

Nick Santini 0 points

  • 6 years ago

So you need to do something like

perch_blog_custom([
        'template' => 'yourtemplate.html',
        'paging'   => false,
        'count'    => 6000,
]);

Then create a blog template for your urls

Dexter Harrison said:

So you need to do something like

perch_blog_custom([
       'template' => 'yourtemplate.html',
       'paging'   => false,
       'count'    => 6000,
]);

Then create a blog template for your urls

Ok I will try that. Thanks!

What would I use for the link in the template? Right now this is what it looks like but it isn't working. What I get is a blank xml page that says "This XML file does not appear to have any style information associated with it. The document tree is shown below."

blog-sitemap.html

<perch:before><?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
</perch:before>
<url>
    <loc><perch:blog id="postURL" /></loc>
</url>
<perch:after>
</urlset>
</perch:after>

blog-sitemap.php

<?php
    header('Content-type: application/xml');
    include('perch/runtime.php');
    perch_blog_custom(array(        
        'template' => 'blog-sitemap.html',
    ));
?>

Why do you have a separate blog-sitemap file?

The normal convention is to have everything in sitemap.xml in the root of your site.

I'd do something like this

<?php
    header('Content-type: application/xml');
    include('perch/runtime.php');
    echo '<?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">';

    perch_pages_navigation([
        'template' => 'sitemap.html',
        'flat' => true,
    ]);

    perch_blog_custom([
        'template' => 'google_sitemap.html',
        'paging'   => false,
        'count'    => 6000,
    ]);

    echo '</urlset>';

then your blog template something like

<url>
    <loc>https://example.com<perch:blog id="postURL" /></loc>
    <changefreq>never</changefreq>
</url>

As for the no style information message that's okay. As long as your sitemap outputs correctly.

Even Google's sitemap has that message https://www.google.co.uk/sitemap.xml

So here is what ended up working,

<?php
    header('Content-type: application/xml');
    include('../perch/runtime.php');
    perch_blog_custom(array(
        'template'=>'blog-sitemap.html',
        'count' => 6000
    ));
?>
<perch:before><?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
</perch:before>
<url>
    <loc>https://example.com<perch:blog id="postURL"/></loc>
</url>
<perch:after>
</urlset>
</perch:after>

Thanks for your help.