How to add virtual pages in sitemap.xml

Jul 1, 2020
By hissy for Developers

Tested on 8.5.4

Generate Sitemap job will generate sitemap.xml with all pages in your sitemap.

You can add additional urls in the sitemap.xml by adding a custom listner to the on_sitemap_xml_ready event.

Express entry detail pages won't included in the sitemap.xml, but you can fix it with this event hook.

Please try to add this example code in your application/bootstrap/app.php.

<?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/', 'view_express_entity', $id]));
            $url->addChild('lastmod', $lastMod);
            $url->addChild('priority', 0.5);
            $url->addChild('changefreq', 'weekly');
        }
    }

    $event->setDocument($xml);
});
Recent Tutorials
Add-On Developers: Get Your Add-Ons Ready for Concrete CMS 9.0
Aug 6, 2021
By andrew.

Concrete CMS 9.0 is coming! But there are some changes in version 9 that might affected your add-ons and themes. This document aims to answer questions about the most common ways that your add-ons might need to be changed, and common problems you'll run into.

Permissions for editors in a multilingual site
Jun 2, 2021
By myq_1.

How to set up a multilingual Concrete CMS site for groups of language-specific editors

Getting Started with Doctrine in Concrete CMS
Jan 20, 2021
By linuxoid.

Doctrine is a very flexible, simple (once you get to know it better) and powerful PHP library for database interactions primarily focused on the ORM = Object Relational Mapping and DBAL = DataBase Abstraction Layer.

How To Upgrade PHP Using the MultiPHP Manager In cPanel
Nov 23, 2020

This article will explain how to upgrade your PHP version using cPanel.

How To Add Google Analytics To Your Website - The easy way
Oct 9, 2020

Adding analytics to your website is an important part of running your website. There’s no need to edit your theme or install a plugin to add a tracking code to Concrete CMS you can do it right from the CMS.

How to Generate Sitemap xml File
Oct 9, 2020

Learn how to create a sitemap.xml in a couple clicks

Was this information useful?
Thank you for your feedback.