Forum

Thread tagged as: Question, Runway

XML Sitemap for Collections

Hi all

I'm trying to create an XML sitemap for collections.

Everything is working fine apart from the last modified date, which I can't seem to get to work.

/sitemap_profiles.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" xmlns:mobile="https://www.google.com/schemas/sitemap-mobile/1.0">';

    perch_collection('Staff Profiles', [
        'template'   => 'about/sitemap_profiles.html'
    ]);

    echo '</urlset>';

/perch/templates/content/about/sitemap_profiles.html

<url>
    <loc>https://www.wardgethinarcher.co.uk/about/meet-team/<perch:content id="profileSlug" /></loc>
    <changefreq>monthly</changefreq>
    <lastmod><perch:pages id="pageModified" format="%Y-%m-%d" /></lastmod>
    <mobile:mobile/>
</url>

I appreciate that <perch:pages /> doesn't work in the content templates but there is no field in the collection template to include that data.

What's the best way to get the page's last modified date to work, please?

Glen Piggott

Glen Piggott 0 points

  • 3 years ago

Hi Glen

Is each profile a separate page or are they just listed out on a single page? If the latter then you don't need to list the items in your sitemap, just the page. If it's the former then you'd need to add a date field to the collection.

Personally I wouldn't worry about having the lastmod in there. It's not essential for a page like this. Unless they are firing people all the time!

Jon

Drew McLellan

Drew McLellan 2638 points
Perch Support

Each collection item should have a _date field - have you tried that?

Just tried <lastmod><perch:content id="_date" format="%Y-%m-%d" /></lastmod> but doesn't seem to work.

There is no _date when using <perch:showall /> on the collection page

For this type of situation I created a modified date field type and included it on my template. It's on GitHub if you want to take a look.