PHP code example of iulyanp / sitemap-generator

1. Go to this page and download the library: Download iulyanp/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/ */

    

iulyanp / sitemap-generator example snippets




use Iulyanp\Sitemap\SitemapConfig;
use Iulyanp\Sitemap\XmlSitemapGenerator;

$config = new SitemapConfig('http://www.google.com', 'http://m.google.com/');
$sitemapGenerator = new XmlSitemapGenerator($config);

// generate some static links
$sitemapGenerator->addItem('/', '1.0', 'daily', 'now');
$sitemapGenerator->addItem('/about', '0.4', 'yearly', 'Jul 08');
$sitemapGenerator->addItem('/contact', '0.7', 'monthly', '11-11-2009');

// create the index sitemap for all generated sitemaps
$sitemapGenerator->createSitemapIndex();



ulyanp\Sitemap\SitemapConfig;
use Iulyanp\Sitemap\SitemapGeneratorInterface;
use Iulyanp\Sitemap\XmlSitemapGenerator;

class AppSitemap
{
    private $sitemapGenerator;

    public function __construct(SitemapGeneratorInterface $sitemapGenerator)
    {
        $this->sitemapGenerator = $sitemapGenerator;
    }
    
    public function generate()
    {
        // generate some static links
        $this->sitemapGenerator->addItem('/', '1.0', 'daily', 'now');
        $this->sitemapGenerator->addItem('/about', '0.8', 'monthly', 'Jun 25');
        $this->sitemapGenerator->addItem('/contact', '0.6', 'yearly', '14-12-2009');

        // create a DB query and dynamically generate the links
        for ($i = 0; $i <= 100000; $i++) {
            $this->sitemapGenerator->addItem('/products/' . $i . '/');
        }

        // create the index sitemap for all generated sitemaps
        $this->sitemapGenerator->createSitemapIndex();
    }
}

$config = new SitemapConfig('http://www.google.com', 'http://m.google.com/');
$config
    ->setPath('/testings/')
    ->setFilename('test')
    ->setBaseUrl('testing');
$sitemapGenerator = new XmlSitemapGenerator($config);

$app = new AppSitemap($sitemapGenerator);
$app->generate();