Quick links: Content - sections - sub sections
EN FR

jResponseSitemap allow you to generate a sitemap, used by search engines like Google.

Retrieve the response object in the controller:


$resp = $this->getResponse('sitemap');

You have then a jResponseSitemap object in $resp.

Restrictions in a sitemap

  • A sitemap file cannot contain more than 50 000 URLs.
  • A sitemap index file cannot declare more than 1000 sitemap files.

Manual generation

Creation of a sitemap is done by adding each URLs you want to declare in the file:


$resp->addUrl($loc, $lastmod, $changefreq, $priority);
  • $loc: URL of the page
  • $lastmod: date of the last modification of the page. format: Y-m-d.
  • $changefreq: Frequency of the page modifications (only these value: always, hourly, daily, weekly, monthly, yearly, never)
  • $priority: priority of the url beside other URL you declare.

Only $loc is required.

Example:


$resp->addUrl(jUrl::get('module~home:index'));
$resp->addUrl(jUrl::get('module~contact:index'), null, 'weekly', 1);

Automatic generation from the urls.xml file

This behavior is only possible if you use the significant url engine.

You just have to call one method:


$resp->importFromUrlsXml();
return $resp;

Index generation

If you have a big web site, it is prefered to have many files, and declare them in an index. You declare by calling this method:


$resp->addSitemap($loc, $lastmod)
  • $loc: URL of a sitemap
  • $lastmod: date of the last modification of the page. format: Y-m-d.

Only $loc is required.

It means that you have to create as many action as you want to generate sitemap files, and declare their URL in the urls.xml file. In an other action, you generate the index. You can call jUrl::get for each sitemap and assign this value to $loc


$resp->addSitemap(jUrl::get('mymodule~sitemap:s1');
$resp->addSitemap(jUrl::get('mymodule~sitemap:s2');
$resp->addSitemap(jUrl::get('mymodule~sitemap:s3');
$resp->addSitemap(jUrl::get('mymodule~sitemap:s4');
return $resp;

(s1, s2, s3 and s4 are actions where you generate a sitemap).

Registering your sitemap into search engines

To give the address of your sitemap to search engines, you can do it manually by filling the corresponding form on the web site of the search engine.

You can also do it automatically, by giving the URL of the registration process of the search engine, to the ping() method:


$sitemapurl = jUrl::get('mymodule~sitemap:index');
$url = 'http'. (empty($_SERVER['HTTPS']) ? '' : 's') .'://'. $_SERVER['HTTP_HOST'] . urlencode($sitemapurl);

// google
$resp->ping('http://www.google.com/webmasters/tools/ping?sitemap=' . $url);

// yahoo
$resp->ping('http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url=' . $url);

// Live
$resp->ping('http://webmaster.live.com/ping.aspx?siteMap='.$url);

// Ask
$resp->ping('http://submissions.ask.com/ping?sitemap=' . $url);