Google Site Map using only MenuManager (and mod_rewrite)

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
User avatar
sjg
Power Poster
Power Poster
Posts: 310
Joined: Thu Jan 27, 2005 5:11 pm
Location: Los Angeles, CA

Google Site Map using only MenuManager (and mod_rewrite)

Post 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!
Many modules available from the http://dev.cmsmadesimple.org
The CMS Made Simple Developer Cookbook is now available from Packt Publishers!
tyman00
Power Poster
Power Poster
Posts: 906
Joined: Tue Oct 24, 2006 5:59 pm

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

Post 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.
If all else fails, use a bigger hammer.
M@rtijn wrote: This is a community. This means that we work together and have the same goal (a beautiful CMS), not that we try to put people down and make their (voluntary) job as difficult as can be.
ed
Forum Members
Forum Members
Posts: 17
Joined: Thu Jan 31, 2008 8:18 pm

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

Post 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
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

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

Post 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...
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
ed
Forum Members
Forum Members
Posts: 17
Joined: Thu Jan 31, 2008 8:18 pm

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

Post 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
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

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

Post 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.
Last edited by kermit on Thu Jun 10, 2010 8:26 am, edited 1 time in total.
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
nielsenrc
New Member
New Member
Posts: 9
Joined: Thu Mar 03, 2011 7:52 pm

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

Post by nielsenrc »

Anyway to exclude sitemap.html from the sitemap? I don't really want that page indexed.
nielsenrc
New Member
New Member
Posts: 9
Joined: Thu Mar 03, 2011 7:52 pm

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

Post 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}

Post Reply

Return to “Tips and Tricks”