4.4.2 2016-07-15 18:44 UTC


Version Status Software License Packagist Version Total Downloads SensioLabsInsight Scrutinizer Code Quality

A tool to generate XML sitemaps

Basic Usage

Generating a urlset sitemap

$urlSet = new Thepixeldeveloper\Sitemap\Urlset(); 

$url = (new Thepixeldeveloper\Sitemap\Url($loc))


Generating a sitemapindex sitemap

$sitemapIndex = new Thepixeldeveloper\Sitemap\SitemapIndex(); 

$url = (new Thepixeldeveloper\Sitemap\Sitemap($loc))


Then pass either SitemapIndex or Urlset to Output to generate output

echo (new Thepixeldeveloper\Sitemap\Output())->getOutput($sitemapIndex);


You can add more specific information to a URL entry, ie video / image information


$subelement = new Thepixeldeveloper\Sitemap\Subelements\Image('https://s3.amazonaws.com/path/to/image');


$subelement = new Thepixeldeveloper\Sitemap\Subelements\Video('thumbnail', 'title', 'description');


$subelement = new Thepixeldeveloper\Sitemap\Subelements\Mobile();


$subelement = new Thepixeldeveloper\Sitemap\Subelements\Link('de', 'http://www.example.com/schweiz-deutsch/');


$subelement = (new Thepixeldeveloper\Sitemap\Subelements\News())
    ->setPublicationDate(new \DateTime())
    ->setPublicationName('Site Name')
    ->setTitle('Some title');

Then you need to add the subelement to the URL

$url = new Thepixeldeveloper\Sitemap\Url('http://www.example.com/1')

and rendering is described above.

Advanced Usage

Processing Instructions

You can add processing instructions on the output as such.

$output = new Thepixeldeveloper\Sitemap\Output();
$output->addProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="/path/to/xslt/main-sitemap.xsl"');

echo $output->getOutput($urlset);

Which will add

<?xml-stylesheet type="text/xsl" href="/path/to/xslt/main-sitemap.xsl"?>

before the document starts.

Indenting output

Output is indented by default, can be turned off as follows

echo (new Thepixeldeveloper\Sitemap\Output())


Name Default Values
setIndented true boolean
setIndentString 4 spaces string

Why should I use this over cartographer?

  • This library has less complexity. All it's going to do is build an object graph and spit it out as XML
  • Has support for a growing list of sub elements ie: mobile and images
  • No dependencies. A library outputting XML doesn't need to rely on Flysystem