1. Go to this page and download the library: Download roumen/sitemap library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
roumen / sitemap example snippets
use Rumenx\Sitemap\Sitemap;
public function sitemap(Sitemap $sitemap)
{
$sitemap->add('https://example.com/', now(), '1.0', 'daily');
$sitemap->add('https://example.com/about', now(), '0.8', 'monthly', images: [
['url' => 'https://example.com/img/about.jpg', 'title' => 'About Us']
]);
// Add more items as needed...
return response($sitemap->render('xml'), 200, ['Content-Type' => 'application/xml']);
}
use Rumenx\Sitemap\Sitemap;
use Symfony\Component\HttpFoundation\Response;
class SitemapController
{
public function sitemap(): Response
{
$sitemap = new Sitemap();
$sitemap->add('https://example.com/', (new \DateTime())->format(DATE_ATOM), '1.0', 'daily');
$sitemap->add('https://example.com/contact', (new \DateTime())->format(DATE_ATOM), '0.5', 'monthly');
// Add more items as needed...
return new Response($sitemap->render('xml'), 200, ['Content-Type' => 'application/xml']);
}
}