PHP code example of muhammetsafak / sitemap-generator
1. Go to this page and download the library: Download muhammetsafak/sitemap-generator 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/ */
muhammetsafak / sitemap-generator example snippets
use \MuhammetSafak\SitemapGenerator\Generator;
$generator = new Generator();
$generator->setBaseURL('https://example.com/');
for ($i = 1; $i <= 3; ++$i) {
$path = "/path/page/" . $i;
$generator->addUrl($path, new DateTime(), [
'changefreq' => 'weekly',
'priority' => '0.6'
]);
}
$generator->save(__DIR__ . '/sitemap.xml', true);
$generator->clear();
use \MuhammetSafak\SitemapGenerator\Generator;
$generator = new Generator();
$generator->setBaseURL('https://example.com/');
$generator->addAlternate('fr', 'https://example.com/fr/');
$generator->addAlternate('de', 'https://example.com/de/')
for ($i = 1; $i <= 3; ++$i) {
$path = "/path/page/" . $i;
$generator->addUrl($path, new DateTime(), [
'changefreq' => 'weekly',
'priority' => '0.6'
]);
}
$generator->save(__DIR__ . '/sitemap.xml', true);
$generator->clear();
use \MuhammetSafak\SitemapGenerator\Generator;
$generator = new Generator(Generator::NEWS);
$generator->setBaseURL('https://example.com/');
$video = [
'thumbnail' => 'https://example.com/thumbs/1.jpg',
'title' => 'Video Title 1',
'description' => 'Video Description Value',
'content_loc' => 'https://example.com/videos/1.mp4',
'player_loc' => 'https://example.com/videoplayer.php?video=1',
'duration' => 600,
'expiration_date' => '2021-11-05T19:20:30+08:00', // or DateTimeInterface object
'rating' => '4.2',
'view_count' => 12345,
'publication_date' => '2012-11-05T19:20:30+08:00', // or DateTimeInterface object
'family_friendly' => true, // [true|false|"yes"|"no"]
'platform' => [
'relationship' => 'allow', // ["allow"|"deny"]
'value' => 'web mobil tv' // "web" "mobil" "tv"
],
'restriction' => [
'relationship' => 'allow', // ["allow"|"deny"]
'value' => 'IE GB US CA'
],
'price' => [
'currency' => 'EUR',
'value' => '1.99'
],
'
use \MuhammetSafak\SitemapGenerator\Generator;
$generator = new Generator(Generator::NEWS);
$generator->setBaseURL('https://example.com/');
$generator->addUrl('/path/page/1', new DateTime(), [
'image' => 'https://example.com/files/image1.jpg'
]);
$generator->addUrl('/path/page/2', new DateTime(), [
'image' => [
'https://example.com/files/image2.jpg',
'https://example.com/files/image3.jpg',
'https://example.com/files/image4.jpg'
]
]);
$generator->save(__DIR__ . '/sitemap.xml', true);
$generator->clear();
use \MuhammetSafak\SitemapGenerator\Generator;
$generator = new Generator(Generator::NEWS);
$generator->setBaseURL('https://example.com/');
for ($i = 1; $i <= 3; ++$i) {
$path = "/path/news/" . $i;
$generator->addUrl($path, new DateTime(), [
'publication' => [
'name' => 'The Example Times',
'language' => 'en'
],
'title' => 'Headline Of Breaking News #' . $i,
]);
}
$generator->save(__DIR__ . '/sitemap.xml', true);
$generator->clear();