havramar/next-php-sitemap-generator

Yet another sitemap generator in PHP.

dev-master 2015-01-14 23:43 UTC

This package is not auto-updated.

Last update: 2020-01-06 03:55:59 UTC


README

Yet another sitemap generator in PHP.

Build Status SensioLabsInsight

Why?

Needed more customizable sitemap generator:

  • switch format output,
  • create only index files basing on config input,
  • helper constants for some values,
  • some other :)

Adding to existing project

composer require havramar/next-php-sitemap-generator:dev-master

How to run

  1. Get composer
curl -sS https://getcomposer.org/installer | php
  1. Install dependencies
php composer.phar install
  1. Create example script example.php
<?php

require_once 'vendor/autoload.php';

$sitemapCreator = new \SitemapGenerator\SitemapCreator();
$sitemapCreator->setDomain('http://www.example.com');

$url = new \SitemapGenerator\Url();
$url->loc = '/home';
$url->changefreq = \SitemapGenerator\Url::FREQ_HOURLY;

$sitemapCreator->addUrl($url);

$indexCreator = $sitemapCreator->buildIndexCreator();
$indexCreator->createIndex('http://www.example.com/sitemaps/');
  1. Run example
php example.php
  1. Two files were created in current directory
  • sitemap-1.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
     <url>
      <loc>http://www.example.com/home</loc>
      <changefreq>hourly</changefreq>
     </url>
    </urlset>
  • sitemap-index-1.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
     <sitemap>
      <loc>http://www.example.com/sitemaps/sitemap-1.xml</loc>
     </sitemap>
    </sitemapindex>

More examples

More examples can be found in tests file.

How to run tests

vendor/bin/phpunit --configuration tests