PHP code example of grozzzny / sitemap
1. Go to this page and download the library: Download grozzzny/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/ */
grozzzny / sitemap example snippets
'aliases' => [
'@webroot' => '@app/web',
],
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'hostInfo' => 'my-site.ru',
'scriptUrl' => '',
'baseUrl' => ''
],
],
'modules' => [
'sitemap' => [
'class' => 'grozzzny\sitemap\SitemapModule',
'domain' => 'https://my-site.ru',
'generatedByLink' => 'https://pr-kenig.ru',
'generatedByName' => 'PRkenig',
'controllerMap' => [
'console' => 'app\commands\SitemapController'
]
]
],
class SitemapController extends ConsoleController
{
public $lastmodStaticPage = ''; // Y-m-d
public $staticPages = [
[
'loc' => '/about', // /about
'lastmod' => '2020-08-19', // Y-m-d
'changefreq' => Sitemap::CHANGEFREQ_MONTHLY,
'priority' => Sitemap::PRIORITY_60,
],
];
protected function dataSitemap()
{
$this->generateArticles();
}
protected function generateArticles()
{
$models = AdminArticles::find()
->andWhere(['active' => true])
->all();
foreach($models as $model){
$this->data_sitemap['articles'][] = array(
'loc' => $model->link,
'lastmod' => Sitemap::lastmodFormat($model->updated_at),
'changefreq' => Sitemap::CHANGEFREQ_MONTHLY,
'priority' => Sitemap::PRIORITY_60,
);
}
}
}
bash
$ php composer.phar