Created
July 1, 2020 10:22
-
-
Save hissy/f064e6321c3c8f8acdb045b6acee3897 to your computer and use it in GitHub Desktop.
[concrete5] Add express entry details into sitemap.xml
This file contains hidden or 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
<?php | |
/* @var Concrete\Core\Application\Application $app */ | |
/* @var Concrete\Core\Console\Application $console only set in CLI environment */ | |
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $director */ | |
$director = $app->make(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class); | |
$director->addListener('on_sitemap_xml_ready', static function ($event) use ($app) { | |
/** @var \Concrete\Core\Page\Sitemap\Event\XmlReadyEvent $event */ | |
$xml = $event->getDocument(); | |
$entity = Express::getObjectByHandle('test'); | |
if (is_object($entity)) { | |
$resolver = $app->make(\Concrete\Core\Url\Resolver\Manager\ResolverManagerInterface::class); | |
$list = new \Concrete\Core\Express\EntryList($entity); | |
$entries = $list->getResults(); | |
/** @var \Concrete\Core\Entity\Express\Entry $entry */ | |
foreach ($entries as $entry) { | |
$id = $entry->getID(); | |
$lastMod = $entry->getDateModified()->format(DateTime::ATOM); | |
$url = $xml->addChild('url'); | |
$url->addChild('loc', $resolver->resolve(['/express/detail/', $id])); | |
$url->addChild('lastmod', $lastMod); | |
$url->addChild('priority', 0.5); | |
$url->addChild('changefreq', 'weekly'); | |
} | |
} | |
$event->setDocument($xml); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment