This post is old. It may contain broken links, missing images and incorrect information.
I’ve been using Perch for over a year now on all kinds of client and personal sites, and it is amazing!
Recently I’ve been looking at improving the performance of sites built with Perch – both from a speed perspective and also in terms of SEO (Search Engine Optimisation).
Here’s how I go about creating a simple sitemap for a site built using Perch:
Create a New Navigation Template
Within the Perch navigation templates folder I create a new file called sitemap.html:
/perch/resources/templates/navigation/sitemap.html
This file contains the following code:
<perch:before><?xml version="1.0" encoding="UTF-8"?>
<urlset >
</perch:before>
<url>
<loc>https://YOURDOMAIN.co.uk<perch:pages id="pagePath" /></loc>
</url>
<perch:after>
</urlset>
</perch:after>
Don’t forget to update YOURDOMAIN with your actual domain name!
Create a Sitemap Page
The second step is to create a new file in the root directory of your website, I call mine sitemap.php. It should contain this:
<?php
header('Content-type: application/xml');
include('perch/runtime.php');
perch_pages_navigation(array(
'template'=>'sitemap.html',
'flat'=>true
));
?>
You could do this as a new Perch page – but that’s unnecessary – it’s simpler to just create an independent new .php file.
This file (sitemap.php) calls the Perch runtime and then spits out the list of pages which make up your site – you can then submit your sitemap to Google via Webmaster Tools, or reference it in your robots.txt file like this:
User-agent: * Allow: / Sitemap: https://YOURDOMAIN.co.uk/sitemap.php
Again – don’t forget to enter your proper domain name.
Conclusions
This is pretty basic – but Google seems happy enough with it. As always, this is more a reference for my benefit that anyone elses, but if it helps you out feel free to make use of the code!