PHP code example of ar2rsoft / sitemap
1. Go to this page and download the library: Download ar2rsoft/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/ */
ar2rsoft / sitemap example snippets
use yii2tech\sitemap\File;
$siteMapFile = new File();
$siteMapFile->writeUrl(['site/index'], ['priority' => '0.9']);
$siteMapFile->writeUrl(['site/about'], ['priority' => '0.8', 'changeFrequency' => File::CHECK_FREQUENCY_WEEKLY]);
$siteMapFile->writeUrl(['site/signup'], ['priority' => '0.7', 'lastModified' => '2015-05-07']);
$siteMapFile->writeUrl(['site/contact']);
$siteMapFile->close();
return [
'id' => 'my-console-application',
'components' => [
'urlManager' => [
'hostInfo' => 'http://example.com',
'baseUrl' => '/',
'scriptUrl' => '/index.php',
],
// ...
],
// ...
];
use yii2tech\sitemap\File;
use app\models\Item;
$query = Item::find()->select(['slug'])->asArray();
$siteMapFileCount = 0;
foreach ($query->each() as $row) {
if (empty($siteMapFile)) {
$siteMapFile = new File();
$siteMapFileCount++;
$siteMapFile->fileName = 'item_' . $siteMapFileCount . '.xml';
}
$siteMapFile->writeUrl(['item/view', 'slug' => $row['slug']]);
if ($siteMapFile->getIsEntriesLimitReached()) {
unset($siteMapFile);
}
}
use yii2tech\sitemap\IndexFile;
$siteMapIndexFile = new IndexFile();
$siteMapIndexFile->writeUp();
php composer.phar