sitemap.xml without any module

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
User avatar
korpirkor
Forum Members
Forum Members
Posts: 100
Joined: Sun Oct 28, 2007 1:15 pm

sitemap.xml without any module

Post 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 :)
Last edited by korpirkor on Sat Apr 10, 2010 9:32 pm, edited 1 time in total.
[url=http://www.polishwebdesign.pl/]Polish WebDesign Cezary Nowak
Projektowanie stron WWW[/ur]
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm

Re: sitemap.xml without any module

Post by RonnyK »

And why arent you using a module, like SitemapMS?

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

Ronny
User avatar
korpirkor
Forum Members
Forum Members
Posts: 100
Joined: Sun Oct 28, 2007 1:15 pm

Re: sitemap.xml without any module

Post 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
[url=http://www.polishwebdesign.pl/]Polish WebDesign Cezary Nowak
Projektowanie stron WWW[/ur]
Post Reply

Return to “Tips and Tricks”