Page 1 of 1

sitemap.xml without any module

Posted: Sat Apr 10, 2010 9:20 pm
by korpirkor
HI :)
I had to create sitemap.xml for all subpages and news so i did it this way:

1. Create page template called sitemap:

Code: Select all

{set_content_type type="text/xml"}<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
{menu template='sitemap' show_all='1' collapse='0'}
{cms_module module="news" summarytemplate="sitemap"}
</urlset>
2. Create menu template called sitemap:

Code: Select all

{if $count > 0}
{assign var='now' value=$smarty.now|strtotime}
{foreach from=$nodelist item=node}
{if $node->url != '#' && $node->url != ''}
<url>
	<loc>{$node->url}</loc>
	<lastmod>{$node->modified|date_format:'%Y-%m-%dT%T-08:00'}</lastmod>
	<changefreq>{assign var='mod' value=$node->modified|strtotime}{math assign='age' equation="(n-m)/86400" n=$smarty.now m=$mod}{if $age < 2}hourly{elseif $age< 14}daily{elseif $age < 30}weekly{else}monthly{/if}</changefreq>
	<priority>{math equation="1/y - x/100" x=$node->index y=$node->depth format="%1\$.2F"}</priority>
</url>
{/if}
{/foreach}
{/if}
its lame way to calculate priority. If anybody know better - tell me :)
x/100 -> 100 its max page count. If you have 500 pages or more, enter x/1000 or something like that

3. Create News template called sitemap:

Code: Select all

{foreach from=$items item=entry}
<url>
	<loc>{$entry->moreurl}</loc>
{if $entry->modified_date}
	<lastmod>{$entry->modified_date|date_format:'%Y-%m-%dT%T-08:00'}</lastmod>
{/if}
	<changefreq>{assign var='mod' value=$entry->modified_date|strtotime}{math assign='age' equation="(n-m)/86400" n=$smarty.now m=$mod}{if $age < 2}hourly{elseif $age< 14}daily{elseif $age < 30}weekly{else}monthly{/if}</changefreq>
	<priority>0.33</priority>
</url>
{/foreach}
4. Create page called sitemap and set template "sitemap" for it. Also unselect option "Show in menu" ;)

5. Edit/Create .htaccess file and insert there:

Code: Select all

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^sitemap.xml$ index.php?page=sitemap [L]
If you use pretty URLs - line RewriteBase / already is there.

6. Add User Tag set_content_type

Code: Select all

if ($params['type'])
{
global $gCms;
$gCms->variables['content-type'] = $params['type'];
}
ps. part of code was posted already on this board by other users - thanks :-)

I Hope that, it will help :)

Re: sitemap.xml without any module

Posted: Sun Apr 11, 2010 5:57 am
by RonnyK
And why arent you using a module, like SitemapMS?

As that is available, and honours the defaults like inactive/hidden etc...

Ronny

Re: sitemap.xml without any module

Posted: Tue Apr 27, 2010 12:37 am
by korpirkor
RonnyK wrote:And why arent you using a module, like SitemapMS?
I had some problems with that module... And for this I can even add support for Gallery Module :-P