2011-06-07 20:37:38 +02:00
|
|
|
# Google Sitemaps Module
|
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
SilverStripe provides support for the Google Sitemaps XML system, enabling
|
|
|
|
Google and other search engines to see all pages on your site. This helps
|
|
|
|
your SilverStripe website rank well in search engines, and to encourage the
|
2011-06-07 20:37:38 +02:00
|
|
|
information on your site to be discovered by Google quickly.
|
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
Therefore, all Silverstripe websites contain a special controller which can be
|
|
|
|
visited: http://yoursite.com/sitemap.xml. This is not a file directly, but
|
2012-07-06 06:44:26 +02:00
|
|
|
rather a custom route which points to the GoogleSitemap controller.
|
2011-06-07 20:37:38 +02:00
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
See http://en.wikipedia.org/wiki/Sitemaps for info on the Google Sitemap
|
2012-07-06 06:44:26 +02:00
|
|
|
format.
|
2011-06-07 20:37:38 +02:00
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
Whenever you publish a new or republish an existing page, SilverStripe can
|
|
|
|
automatically inform Google of the change, encouraging a Google to take notice.
|
|
|
|
If you install the SilverStripe Google Analytics module, you can see if Google
|
2012-07-06 06:44:26 +02:00
|
|
|
has updated your page as a result.
|
2011-06-07 20:37:38 +02:00
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
By default, SilverStripe informs Google that the importance of a page depends
|
|
|
|
on its position of in the sitemap. "Top level" pages are most important, and
|
|
|
|
the deeper a page is nested, the less important it is. (For each level,
|
2011-06-07 20:37:38 +02:00
|
|
|
Importance drops from 1.0, to 0.9, to 0.8, and so on, until 0.1 is reached).
|
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
In the CMS, in the Settings tab for each page, you can set the importance
|
2012-07-06 06:44:26 +02:00
|
|
|
manually, including requesting to have the page excluded from the sitemap.
|
2011-06-07 20:37:38 +02:00
|
|
|
|
2013-01-15 10:29:59 +01:00
|
|
|
## Configuration
|
|
|
|
|
|
|
|
Most module configuration is done via the SilverStripe Config API. Create a new
|
|
|
|
config file `mysite/_config/googlesitemaps.yml` with the following outline:
|
|
|
|
|
|
|
|
---
|
|
|
|
Name: customgooglesitemaps
|
|
|
|
After: googlesitemaps
|
|
|
|
---
|
2017-10-19 22:05:18 +02:00
|
|
|
Wilr\GoogleSitemaps\GoogleSitemap:
|
2013-01-15 10:29:59 +01:00
|
|
|
enabled: true
|
|
|
|
objects_per_sitemap: 1000
|
|
|
|
google_notification_enabled: false
|
|
|
|
use_show_in_search: true
|
|
|
|
|
|
|
|
You can now alter any of those properties to set your needs. A popular option
|
|
|
|
is to turn on automatic pinging so that Google is notified of any updates to
|
|
|
|
your page. You can set this in the file we created in the last paragraph by
|
|
|
|
editing the `google_notification_enabled` option to true
|
|
|
|
|
|
|
|
---
|
|
|
|
Name: customgooglesitemaps
|
|
|
|
After: googlesitemaps
|
|
|
|
---
|
2017-10-19 22:05:18 +02:00
|
|
|
Wilr\GoogleSitemaps\GoogleSitemap:
|
2013-01-15 10:29:59 +01:00
|
|
|
enabled: true
|
|
|
|
objects_per_sitemap: 1000
|
|
|
|
google_notification_enabled: true
|
|
|
|
use_show_in_search: true
|
2011-06-07 20:37:38 +02:00
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
### Bing Ping Support
|
|
|
|
|
|
|
|
To ping Bing whenever your sitemap is updated, set `bing_notification_enabled`
|
|
|
|
|
|
|
|
---
|
|
|
|
Name: customgooglesitemaps
|
|
|
|
After: googlesitemaps
|
|
|
|
---
|
2017-10-19 22:05:18 +02:00
|
|
|
Wilr\GoogleSitemaps\GoogleSitemap:
|
2016-09-16 22:27:16 +02:00
|
|
|
enabled: true
|
|
|
|
bing_notification_enabled: true
|
|
|
|
|
2012-07-06 06:44:26 +02:00
|
|
|
### Including DataObjects
|
2011-06-07 20:37:38 +02:00
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
The module provides support for including DataObject subclasses as pages in the
|
2012-07-06 06:44:26 +02:00
|
|
|
SiteTree such as comments, forum posts and other pages which are stored in your
|
|
|
|
database as DataObject subclasses.
|
2011-06-07 20:37:38 +02:00
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
To include a DataObject instance in the Sitemap it requires that your subclass
|
2012-07-06 06:44:26 +02:00
|
|
|
defines two functions:
|
2011-06-07 20:37:38 +02:00
|
|
|
|
|
|
|
* AbsoluteLink() function which returns the URL for this DataObject
|
|
|
|
* canView() function which returns a boolean value.
|
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
The following is a barebones example of a DataObject called 'MyDataObject'. It
|
|
|
|
assumes that you have a controller called 'MyController' which has a show method
|
2012-07-06 06:44:26 +02:00
|
|
|
to show the DataObject by its ID.
|
2011-06-07 20:37:38 +02:00
|
|
|
|
|
|
|
<?php
|
2016-09-16 22:27:16 +02:00
|
|
|
|
2017-10-19 22:05:18 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
|
2011-06-07 20:37:38 +02:00
|
|
|
class MyDataObject extends DataObject {
|
2016-09-16 22:27:16 +02:00
|
|
|
|
2013-08-27 23:02:21 +02:00
|
|
|
function canView($member = null) {
|
2011-06-07 20:37:38 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-09-16 22:27:16 +02:00
|
|
|
|
2011-06-07 20:37:38 +02:00
|
|
|
function AbsoluteLink() {
|
|
|
|
return Director::absoluteURL($this->Link());
|
|
|
|
}
|
2016-09-16 22:27:16 +02:00
|
|
|
|
2011-06-07 20:37:38 +02:00
|
|
|
function Link() {
|
|
|
|
return 'MyController/show/'. $this->ID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
After those methods have been defined on your DataObject you now need to tell
|
2012-07-06 06:44:26 +02:00
|
|
|
the Google Sitemaps module that it should be listed in the sitemap.xml file. To
|
|
|
|
do that, include the following in your _config.php file.
|
2011-06-07 20:37:38 +02:00
|
|
|
|
2017-10-19 22:05:18 +02:00
|
|
|
use Wilr\GoogleSitemaps\GoogleSitemap;
|
|
|
|
|
2011-06-07 20:37:38 +02:00
|
|
|
GoogleSitemap::register_dataobject('MyDataObject');
|
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
If you need to change the frequency of the indexing, you can pass the change
|
|
|
|
frequency (daily, weekly, monthly) as a second parameter to register_dataobject(), So
|
2012-07-06 06:44:26 +02:00
|
|
|
instead of the previous code you would write:
|
2011-06-07 20:37:38 +02:00
|
|
|
|
2017-10-19 22:05:18 +02:00
|
|
|
use Wilr\GoogleSitemaps\GoogleSitemap;
|
|
|
|
|
2016-09-16 22:27:16 +02:00
|
|
|
GoogleSitemap::register_dataobject('MyDataObject', 'daily');
|
|
|
|
|
2011-06-07 20:37:38 +02:00
|
|
|
See the following blog post for more information:
|
|
|
|
|
2013-01-17 22:49:32 +01:00
|
|
|
http://www.silvercart.org/blog/dataobjects-and-googlesitemaps/
|
|
|
|
|
|
|
|
### Including custom routes
|
|
|
|
|
|
|
|
Occasionally you may have a need to include custom url's in your sitemap for
|
|
|
|
your Controllers and other pages which don't exist in the database. To update
|
|
|
|
the sitemap to include those links call register_routes() with your array of
|
|
|
|
urls to include.
|
|
|
|
|
2017-10-19 22:05:18 +02:00
|
|
|
use Wilr\GoogleSitemaps\GoogleSitemap;
|
|
|
|
|
2013-01-17 22:49:32 +01:00
|
|
|
GoogleSitemap::register_routes(array(
|
|
|
|
'/my-custom-controller/',
|
|
|
|
'/Security/',
|
|
|
|
'/Security/login/'
|
|
|
|
));
|