PHP code example of arkdevuk / sitemap-builder

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

    

arkdevuk / sitemap-builder example snippets




namespace App;


lder\classes\Sitemap;
use ArkdevukSitemapBuilder\classes\SitemapContainer;
use ArkdevukSitemapBuilder\classes\SitemapEntry;
use ArkdevukSitemapBuilder\classes\SitemapEntryImage;

$baseUrl = 'https://mywebsite.tld';

$container = new SitemapContainer($baseUrl, __DIR__.DIRECTORY_SEPARATOR.'example1');

$sitemap = new Sitemap('page');

$entry = new SitemapEntry();
$entry
    ->setLocation('/test')
    ->setChangeFrequency(SitemapEntry::CHANGE_WEEKLY)
    ->setPriority(1)
    ->setLastModDateTime(new \DateTime('2020-12-10'));

$media = new SitemapEntryImage($baseUrl.'/assets/images/image.jpeg');
$media
    ->setCaption('A test image for the purpose of the example')
    ->setGeoLocation('Aurillac, Cantal, France')
    ->setTitle('Image Title')//->setLicence('https://creativecommons.org/licenses/by-nc-nd/4.0/')
;

$entry->setMedia($media);

$sitemap->addEntry($entry);

$container->addSitemap($sitemap);


$container->compile();