PHP code example of ayiu / sitemap-php

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

    

ayiu / sitemap-php example snippets


	

   	use SitemapPHP\Sitemap;

	$sitemap = new Sitemap('http://example.com');

	$sitemap->setPath('xmls/');

	$sitemap->setFilename('customsitemap');

	$sitemap->addItem('/', '1.0', 'daily', 'Today');
	$sitemap->addItem('/about', '0.8', 'monthly', 'Jun 25');
	$sitemap->addItem('/contact', '0.6', 'yearly', '14-12-2009');
	$sitemap->addItem('/otherpage');

	$sitemap->addItem('/projects', '0.8')->addItem('/somepage')->addItem('/hiddenpage', '0.4', 'yearly', '01-01-2011')->addItem('/rss');

	$query = Doctrine_Query::create()
					->select('p.created_at, p.slug')
					->from('Posts p')
					->orderBy('p.id DESC')
					->useResultCache(true);
	$posts =  $query->fetchArray(array(), Doctrine_Core::HYDRATE_ARRAY);
    	foreach ($posts as $post) {
        	$sitemap->addItem('/post/' . $post['slug'], '0.6', 'weekly', $post['created_at']);
    	}

	$sitemap->setDomain('http://blog.example.com');

	$sitemap->createSitemapIndex('http://example.com/sitemap/', 'Today');
shell
composer