KK wrote: Hi Potato,
We can use Couch itself to create a dynamically generated sitemap.
This is what a typical sitemap looks like (used
http://www.xml-sitemaps.com to get this and trimmed down the entries to only two)
- Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->
<url>
<loc>http://www.yoursite.com/</loc>
<lastmod>2012-09-10T13:30:35+00:00</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>http://www.yoursite.com/about-us/</loc>
<lastmod>2012-09-10T13:30:35+00:00</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>
It is just a XML list of pages.
The repeating element here is the <url>..</url> block that contains information about each page in the site.
If we were to generate such a list using Couch, we can create a separate template to output the XML list (let us call it 'sitemap.php').
In this template, we paste the code above.
We'll have to modify the XML part as it has some quirks that have been discussed in our docs where we create a RSS feed (
http://www.couchcms.com/docs/concepts/rss-feeds.html).
To output the <url>..</url> blocks for each page, we use only one block and then enclose with
cms:pages tag.
A typical Couch site consists of more than one template, so we either use the cms:pages loop multiple times specifying a different template (the 'masterpage' parameter) each time or for a more generic solution, we can use the cms:templates tag (
http://www.couchcms.com/docs/tags-refer ... tes-1.html) to loop through the available non-hidden templates and feed the names to cms:pages tag.
Here is a complete working 'sitemap.php' template. You can download it and use it as-in in your site:
sitemap.zip
- Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:content_type 'text/xml' /><cms:concat '<' '?xml version="1.0" encoding="' k_site_charset '"?' '>' />
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<cms:templates order='asc' >
<cms:pages masterpage=k_template_name>
<url>
<loc><cms:show k_page_link /></loc>
<lastmod><cms:date "<cms:if k_page_modification_date='0000-00-00 00:00:00'><cms:show k_page_date /><cms:else /><cms:show k_page_modification_date /></cms:if>" format='Y-m-d\TH:i:s+00:00' gmt='1' /></lastmod>
<changefreq>daily</changefreq>
</url>
</cms:pages>
</cms:templates>
</urlset>
<?php COUCH::invoke(); ?>
Hope this helps. Do let me know.
P.S. If you have not yet turned caching on for your site (in config.php), now is the time to do so