Skip to content

tihoho/phpSitemapGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

phpSitemapGenerator

A simple class for creating sitemap via php

Gratitude or rotten tomatoes send here: [email protected]

Examples of use

<?php

use Silentlabs\SitemapGenerator as Sitemap;

$sitemap = new Sitemap('https://mydomain.com');
$sitemap->addLink('somelink1.html');
$sitemap->addLink('somelink2.php');
$sitemap->addLink('somelinkN');
$sitemap->build();

$savePath = '/var/www/mydomain.com/public/sitemap.xml';

if($sitemap->save($savePath)) {
	echo 'Success!';
} else {
	echo 'Fail!';
}
OR
<?php

use Silentlabs\SitemapGenerator as Sitemap;

$sitemap = (new Sitemap())
	->setDomain('https://mydomain.com')
	->addLink('somelink1.html')
	->build()
	->save('path/to/save');

if($sitemap->isSaved) {
	echo 'Success!';
} else {
	echo 'Fail!';
}
OR
<?php

use Silentlabs\SitemapGenerator as Sitemap;

$links = [
	'mylink',
	'mylink2.php',
	'mylink3.html',
	'mylink_N'
];

$sitemap = (new Sitemap())
	->setDomain('https://mydomain.com')
	->setDefaults([
		'changefreq' => 'weekly',
		'lastmod' => date('Y-m-d'),
	])
	->ignorePriority();
	
foreach($links as $link)
	$sitemap->addLink($link);
	
echo $sitemap->build()->get(); // Return a sitemap structure
OR something else, because it class a very flexible :)

Happy new code!

About

A simple class for creating sitemap via php

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages