Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #37 from tsanchev/master
Browse files Browse the repository at this point in the history
multilingual sitemap
  • Loading branch information
himiklab authored Feb 11, 2019
2 parents a3ab0f6 + 7ac455b commit e680cb5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ to the `require` section of your application's `composer.json` file.
'loc' => Url::to($model->url, true),
'lastmod' => strtotime($model->lastmod),
'changefreq' => SitemapBehavior::CHANGEFREQ_DAILY,
'priority' => 0.8
'priority' => 0.8,
'xhtml:link' => [
[
'hreflang' => 'en',
'href' => Url::to(['url_en', true),
],
[
'hreflang' => 'de',
'href' => Url::to(['url_de', true),
],
//...
],
];
}
],
Expand Down
4 changes: 4 additions & 0 deletions behaviors/SitemapBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public function generateSiteMap()
if (isset($urlData['images'])) {
$result[$n]['images'] = $urlData['images'];
}

if (isset($urlData['xhtml:link'])) {
$result[$n]['xhtml:link'] = $urlData['xhtml:link'];
}

++$n;
}
Expand Down
8 changes: 7 additions & 1 deletion views/default/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<?php foreach ($urls as $url): ?>
<url>
<loc><?= htmlspecialchars(yii\helpers\Url::to($url['loc'], true)) ?></loc>
Expand All @@ -25,6 +26,11 @@
<?php if (isset($url['priority'])): ?>
<priority><?= $url['priority'] ?></priority>
<?php endif; ?>
<?php if (isset($url['xhtml:link'])): ?>
<?php foreach ($url['xhtml:link'] as $link): ?>
<xhtml:link rel="alternate" hreflang="<?= $link['hreflang'] ?>" href="<?= $link['href'] ?>" />
<?php endforeach; ?>
<?php endif; ?>
<?php if (isset($url['news'])): ?>
<news:news>
<news:publication>
Expand Down

0 comments on commit e680cb5

Please sign in to comment.