Page 1 of 1

Google Site Map using only MenuManager (and mod_rewrite)

Posted: Thu Nov 19, 2009 11:38 pm
by sjg
Here's a fun trick:

Create a MenuManager template called "google_sitemap":

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.90">
{if $count > 0}
{assign var='now' value=$smarty.now|strtotime}
<url>
{foreach from=$nodelist item=node}
 <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>0.5</priority>
  </url>
{/foreach}
{/if}
</urlset>
Create a page called "sitemap":

Code: Select all

{menu template='google_sitemap' show_all=1 collapse=0}
Uncheck "show in menu" if you want.

Update your .htaccess file:

Code: Select all

php_flag magic_quotes_gpc Off
php_flag register_globals Off

# Make sure you have Options FollowSymLinks
# and Allow on
#RewriteEngine On

#Rewrites page.shtml as index.php?page
#RewriteRule ^(.+)\.html$ index.php?page=$1

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^sitemap.xml$ index.php?page=sitemap&showtemplate=false [L]


#Rewrites page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

Voila! Now http://www.yoursite.com/sitemap.xml will give a Google site map. And you can customize it based on extra page attributes, for example, to set the priorities or to hide classes of pages from the map!

Re: Google Site Map using only MenuManager (and mod_rewrite)

Posted: Fri Nov 27, 2009 5:33 pm
by tyman00
Nice!

Another note is you could use some fancy smarty syntax to change the priority of the page using one of the "Extra#" page attributes or by doing some if/else if statements based off of the  $node->modified parameter.

Re: Google Site Map using only MenuManager (and mod_rewrite)

Posted: Sat Feb 20, 2010 5:29 pm
by ed
I have tried this on the latest version, and all I get is a unstyled listing oin my sitemap page:

http://domain.co.uk.34spreview.com/&nbsp; 2010-02-13T18:29:19-08:00  daily  0.5    http://domain.34spreview.com/how-cmsms-works.html&nbsp; 2010-02-18T20:27:30-08:00  hourly  0.5    http://domain.co.uk.34spreview.com/how- ... .html&nbsp; 2009-05-12T20:12:30-08:00  monthly  0.5    http://domain.co.uk.34spreview.com/how- ... .html&nbsp; 2009-05-12T20:13:19-08:00  monthly  0.5 

and so on

and a sitemap.xml file is not created.

I have searched forums for any help - not luck

Any ideas please?

Thanks

Re: Google Site Map using only MenuManager (and mod_rewrite)

Posted: Fri Jun 04, 2010 2:09 am
by kermit
ed wrote: I have tried this on the latest version, and all I get is a unstyled listing oin my sitemap page:

http://domain.co.uk.34spreview.com/&nbsp; 2010-02-13T18:29:19-08:00  daily  0.5    http://domain.34spreview.com/how-cmsms-works.html&nbsp; 2010-02-18T20:27:30-08:00  hourly  0.5    http://domain.co.uk.34spreview.com/how- ... .html&nbsp; 2009-05-12T20:12:30-08:00  monthly  0.5    http://domain.co.uk.34spreview.com/how- ... .html&nbsp; 2009-05-12T20:13:19-08:00  monthly  0.5   

and so on

and a sitemap.xml file is not created.
the file isn't "created", it is generated and served on-the-fly, so you won't find a "sitemap.xml" anywhere in your web space.

and as far as format goes, view that "unformatted" page's source...

Re: Google Site Map using only MenuManager (and mod_rewrite)

Posted: Sun Jun 06, 2010 10:19 am
by ed
Kermit,

Thank a lot for your reply.  I think I must have made a fundamental error somewhere.

I understand about making a Menu Manager Template.  It seems clear although I have not done one yet - are there any Gotchas!?

But where does this code go in the page:

Code: Select all

{menu template='google_sitemap' show_all=1 collapse=0}
Thanks for your help - much appreciated

Re: Google Site Map using only MenuManager (and mod_rewrite)

Posted: Thu Jun 10, 2010 7:06 am
by kermit
"internal page link" content type creates duplicate entries in sitemap (itself plus its target, which would be added to the sitemap by its own menu entry)... "external link" content type entries shouldn't be included either.

in the menu template:

just before add  {if $node->type eq 'content'}
just after add  {/if}

to limit entries to just 'content' pages.

_____

for automatically assigning priority based on hierarchy, you can use $node->depth,  but i went a different way and came up with:

put before just after the first mod above (if used):
   {assign var='lvl' value=$node->hierarchy|substr_count:'.'}

replace the 0.5 between and with:
   {if $lvl eq '0'}0.9{elseif $lvl eq '1'}0.7{elseif $lvl eq '2'}0.5{else}0.3{/if}

first level pages (based on overall site hierarchy) will be 0.9, second level (e.g. 2.2) will be 0.7, third level (2.2.4) will be 0.5 and fourth (and lower) level pages (e.g. 2.2.4.9) will be 0.3.

before altering page priority in your sitemap, please understand what priority is and what it does (and does not) do. it does NOT affect your site's overall rankings in results, it only tells google what pages you believe are more important relative to others on your own site only.

_____
ed wrote: But where does this code go in the page:

Code: Select all

{menu template='google_sitemap' show_all=1 collapse=0}
just like the OP says. create a new page, put that in its content block.

Re: Google Site Map using only MenuManager (and mod_rewrite)

Posted: Thu Mar 03, 2011 7:54 pm
by nielsenrc
Anyway to exclude sitemap.html from the sitemap? I don't really want that page indexed.

Re: Google Site Map using only MenuManager (and mod_rewrite)

Posted: Wed Mar 09, 2011 6:31 pm
by nielsenrc
Fixed. Revise the code to this:

Code: Select all


{if $node->alias !== "sitemap"}
<url>
    <loc>{$node->url}</loc>
    <lastmod>{$node->modified|date_format:'%Y-%m-%dT%T-08:00'}</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.5</priority>
  </url>
{/if}