public function SitemapGenerator::generate_sitemap_index in Simple XML sitemap 8
Generates and returns the sitemap index.
Parameters
array $sitemap: All sitemap chunks keyed by the chunk ID.
Return value
string sitemap index
File
- src/
SitemapGenerator.php, line 100 - Contains \Drupal\simplesitemap\SitemapGenerator.
Class
- SitemapGenerator
- SitemapGenerator class.
Namespace
Drupal\simplesitemapCode
public function generate_sitemap_index($sitemap) {
$writer = new XMLWriter();
$writer
->openMemory();
$writer
->setIndent(TRUE);
$writer
->startDocument(self::XML_VERSION, self::ENCODING);
$writer
->startElement('sitemapindex');
$writer
->writeAttribute('xmlns', self::XMLNS);
foreach ($sitemap as $chunk_id => $chunk_data) {
$writer
->startElement('sitemap');
$writer
->writeElement('loc', $GLOBALS['base_url'] . '/sitemaps/' . $chunk_id . '/' . 'sitemap.xml');
$writer
->writeElement('lastmod', date_iso8601($chunk_data->sitemap_created));
$writer
->endElement();
}
$writer
->endElement();
$writer
->endDocument();
return $writer
->outputMemory();
}