-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to add custom entries to the sitemap
- Loading branch information
Showing
6 changed files
with
176 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace SeoMaestro; | ||
|
||
use ProcessWire\WireData; | ||
|
||
class SitemapItem extends WireData | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
||
$this->set('loc', ''); | ||
$this->set('lastmod', ''); | ||
$this->set('priority', 0.5); | ||
$this->set('changefreq', 'monthly'); | ||
$this->set('alternates', []); | ||
} | ||
|
||
/** | ||
* Add an alternate URL for another language. | ||
* | ||
* @param string $languageCode | ||
* @param string $url | ||
* | ||
* @return \SeoMaestro\SitemapItem | ||
*/ | ||
public function addAlternate($languageCode, $url) | ||
{ | ||
$alternates = $this->get('alternates'); | ||
$alternates[$languageCode] = $url; | ||
$this->set('alternates', $alternates); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,18 @@ | ||
<?php namespace ProcessWire; ?> | ||
<?php /** @var $pages \ProcessWire\PageArray */ ?> | ||
<?php /** @var $languages \ProcessWire\PageArray */ ?> | ||
<?php /** @var $items \SeoMaestro\SitemapItem[] */ ?> | ||
<?php echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; ?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"> | ||
<?php foreach ($pages as $page): ?> | ||
<?php if ($hasLanguageSupport && $hasLanguageSupportPageNames): ?> | ||
<?php foreach ($languages ?: [] as $language): ?> | ||
<?php if (!$page->viewable($language)) continue; ?> | ||
<?php foreach ($items as $item): ?> | ||
<url> | ||
<loc><?= $baseUrl ? $baseUrl . $page->localUrl($language) : $page->localHttpUrl($language) ?></loc> | ||
<lastmod><?= date('c', $page->modified) ?></lastmod> | ||
<changefreq><?= $page->seoMaestroSitemapData->changeFrequency ?></changefreq> | ||
<priority><?= $page->seoMaestroSitemapData->priority ?></priority> | ||
<?php foreach ($languages as $language): ?> | ||
<?php if (!$page->viewable($language)) continue; ?> | ||
<xhtml:link rel="alternate" hreflang="<?= $language->isDefault() ? $defaultLanguageCode : $language->name ?>" href="<?= $baseUrl ? $baseUrl . $page->localUrl($language) : $page->localHttpUrl($language) ?>"/> | ||
<loc><?= $item->loc ?></loc> | ||
<?php if ($item->lastmod): ?> | ||
<lastmod><?= $item->lastmod ?></lastmod> | ||
<?php endif ?> | ||
<changefreq><?= $item->changefreq ?></changefreq> | ||
<priority><?= $item->priority ?></priority> | ||
<?php foreach ($item->alternates as $langCode => $url): ?> | ||
<xhtml:link rel="alternate" hreflang="<?= $langCode ?>" href="<?= $url ?>"/> | ||
<?php endforeach ?> | ||
</url> | ||
<?php endforeach ?> | ||
<?php else: ?> | ||
<url> | ||
<loc><?= $baseUrl ? $baseUrl . $page->url : $page->httpUrl ?></loc> | ||
<lastmod><?= date('c', $page->modified) ?></lastmod> | ||
<changefreq><?= $page->seoMaestroSitemapData->changeFrequency ?></changefreq> | ||
<priority><?= $page->seoMaestroSitemapData->priority ?></priority> | ||
</url> | ||
<?php endif ?> | ||
<?php endforeach ?> | ||
</urlset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters