Forum

Thread tagged as: Question, Add-on-development, Blog

But I used the exact code and it did not work. I was hoping Perch would be OK to use without knowing any PHP as I am a Designer not a coder.

For now I will have to leave the blog posts out!

Hi Sarah,

Clive has written a good run-through of creating sitemaps that include Blog posts, you can find it here:

https://www.cvwdesign.com/blog/creating-google-sitemaps-with-perch

Hope that helps a bit

Hi Mike

Thanks for the link and that makes more sense and puts things into more content for me. I am still having issues though, here is what I now have after following your guide.

So I have a sitemap.php file in the root with the following code...

<?php
    header('Content-type: application/xml');
    include('perch/runtime.php');
    perch_pages_navigation(array(
        'template'=>'sitemap.html',
        'flat' => true,
        'hide-extensions' => true
      ));

    perch_blog_custom(array(
         'template' => 'sitemap-blog.html',
         'sort'=>'postDateTime',
         'sort-order'=>'DESC',
         'count' => 3000
     ));
echo '</urlset>';
?>

Then I have a sitemap.html file saved in templates/navigation with the following code...

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

<url>
    <loc>https://www.whittledesignstudio.com<perch:pages id="pagePath" /></loc>
    <changefreq>monthly</changefreq>
    <priority>1.00</priority>
</url>

<perch:after>
</urlset>
</perch:after>

And a separate file called sitemap-blog.html saved in templates/blog with the following code...

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

    <url>
     <loc>https://www.whittledesignstudio.com<perch:blog id="postURL" /></loc>
     <changefreq>monthly</changefreq>
     <priority>0.80</priority>
    </url>

<perch:after>
</urlset>
</perch:after>

No when I go to https://www.whittledesignstudio.com/sitemap.php I get errors.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You appear to have two XML documents, rather than one. You only need one of these at the start:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">

and then one of these at the end:

</urlset>

You'll need to update your templates so that it all becomes one cohesive set.

Hi Drew,

This is what the instructions say to do on the link provided by Mike.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You currently have two XML documents, and Drew's reply explains what you need to do to fix the problem.

I have one file in the root called sitemap.php with the following code...

<?php header('Content-type: application/xml'); include('perch/runtime.php'); perch_pages_navigation(array( 'template'=>'sitemap.html', 'flat' => true, 'hide-extensions' => true ));

perch_blog_custom(array(
     'template' => 'sitemap-blog.html',
     'sort'=>'postDateTime',
     'sort-order'=>'DESC',
     'count' => 3000
 ));

echo '</urlset>'; ?>

The two html files it refers to are separate files in the templates folder as per the instructions from Mike.

I just do not know why this has to be so complicated!

Hi Sarah,

As Drew said you are declaring the XML twice, as it is included in both the sitemap.html and sitemap-blog.html templates. You will see on Clive's example he has included this on the page rather than in the templates themselves, to avoid this repetition. I think you need something like this (though not tested it):

<?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(array( 
'template'=>'sitemap.html', 
'flat' => true, 
'hide-extensions' => true 
));  

perch_blog_custom(array( 
'template' => 'sitemap-blog.html',
'sort'=>'postDateTime',
'sort-order'=>'DESC',
'count' => 3000
)); 
echo '</urlset>'; ?>

sitemap.html

<url> 
<loc>https://www.whittledesignstudio.com<perch:pages id="pagePath" /></loc>
<changefreq>monthly</changefreq>
<priority>1.00</priority>
</url>

sitemap-blog.html

<url>
<loc>https://www.whittledesignstudio.com<perch:blog id="postURL" /></loc>
<changefreq>monthly</changefreq>
<priority>0.80</priority>
</url>

Thanks Mike, that has done it!

I just did not know what went where as I am not too familiar with PHP etc...

Thanks for your help

No worries - if you get chance mark that as the solution, I am trying to catch Drew's points score :)

Thanks Mike, just done it