customizing sitemap.xml in concrete5
I had to customize sitemap.xml for my concrete5 to suit my needs. You might find it useful I hope.
So, the first problem is that change frequency for all pages defaults to ‘monthly’. There are 2 ways to solve this problem:
If you want to change ‘monthly’ to another value (for example, ‘weekly’) for all pages, the best solution is to simply hardcode ‘concrete/jobs/generate_sitemap.php’:
if ($changefreq == '') {
$changefreq = 'monthly';
}
Change the variable to whatever you like: ‘yearly’, ‘monthly’, ‘weekly’, ‘daily’ or ‘hourly’. Of course it’s better to use the real change frequency.
If you want to have the ability specifying custom change frequency page-by-page, you should create page attribute: ‘sitemap_changefreq’
Go to c5 Dashboard, then open ‘Page Types’ and click ‘Add attribute’ button :
Handle – sitemap_changefreq
Type – Select menu
Searchable? – No
Name – Sitemap.xml change frequency
Values (one by line):
always
hourly
daily
weekly
monthly
yearly
never
When ready, click ‘Add’. Now you can open ‘Properties’ for a page, select ‘Sitemap.xml change frequency’ in ‘Custom fields’ dropdown and set desired change frequency.
The same with priority field. Here is the code in ‘concrete/jobs/generate_sitemap.php’:
if ($priority == '') {
$priority = '0.5';
}
The handle of the custom page attribute should be sitemap_priority. You can leave the field as text or select dropdown with some predefined set of values (for example, I’ve added select with values 0.0,0.1,…,1.0)
The next problem I faced with is that by default concrete 5 cms adds some pages to sitemap that I don’t like to be present there. Such as:
/download_file
/login
/index.php?cID=1 (duplicate of /)
I’ve added the following code in ‘generate_sitemap.php’:
$exclude_urls = array(
'http://www.mydomain.com/index.php?cID=1',
'http://www.mydomain.com/login',
'http://www.mydomain.com/download_file'
);
if (in_array($cPath,$exclude_urls))
continue;
Just before
if ($changefreq == '') {
$changefreq = 'monthly';
}
Finally, my sitemap.xml seems to look exactly like I want it.
P.S. If anybody doesn’t know how to generate sitemap.xml with concrete5: Go to Dashboard, then to Maintenance, and click Run checked (make sure appropriate task is selected)
April 3rd, 2009 at 3:24 am
Nice reading today. It’s a great info for me who just begin to building my website with C5. Thanks Guy.
Be blessed.
Isyaias
May 7th, 2009 at 12:08 pm
Denis,
Thanks for the post – I’ve added your site to my feedreader.
I started using C5, but am unable to generate the site map. When I try I get a message stating …public_html/sitemap.xml is not writable.
I’m using C5 hosting so I went to the cPanel, file manager, looked and didn’t see a /sitemap.xml so I created a file using that name and tried running again, but got the same message.
I checked properties and it indicates it is writable for user only not group or world. Execute is unchecked.
Any help or suggestions would be much appreciated.
May 8th, 2009 at 1:38 am
Upload an empty sitemap.xml file to your public_html directory and set file permissions as 666. This should help.