PHP code example of jeroendesloovere / sitemap
1. Go to this page and download the library: Download jeroendesloovere/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/ */
jeroendesloovere / sitemap example snippets
namespace App\SitemapProviders;
use JeroenDesloovere\Sitemap\Item\ChangeFrequency;
use JeroenDesloovere\Sitemap\Provider\SitemapProvider;
use JeroenDesloovere\Sitemap\Provider\SitemapProviderInterface;
class NewsArticleSitemapProvider extends SitemapProvider implements SitemapProviderInterface
{
/** @var NewsArticleRepository */
private $articleRepository;
public function __construct(NewsArticleRepository $articleRepository)
{
$this->articleRepository = $articleRepository;
// `NewsArticle::class` would even be better then just `NewsArticle`
// because you can then use it with doctrine events.
parent::__construct('NewsArticle');
}
public function createItems(): void
{
/** @var Article[] $articles */
$articles = $this->articleRepository->findAll();
foreach ($articles as $article) {
$this->createItem('/nl/xxx/url-to-article', $article->getEditedOn(), ChangeFrequency::monthly());
}
}
}