PHP code example of aalfiann / sitemap-manager

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

    

aalfiann / sitemap-manager example snippets



use \SitemapManager\SitemapIndex;

$sm = new SitemapIndex;

// Create blank custom sitemap index
$sm->path = 'sitemap-index.xml';
$sm->create();

// Set the first sitemap file
$sm->path = 'sitemap-index.xml';
// Set the last sitemap file (will increment automatically)
$sm->setLastFile();

// Check the url in all sitemap files
$url = 'http://yourdomain.com/sitemap-test.xml';
if(!$sm->find($url)){
    $sm->addBlock($url)
        ->addLastMod(date('Y-m-d'))
        ->save();
}

$sm->path = 'sitemap-index.xml';
for ($i=1;$i<10;$i++){
    $sm->addBlock('http://yourdomain.com/sitemap-test-'.$i.'.xml')
        ->addLastMod(date('Y-m-d'))
        ->enqueue();
}
$sm->save();

$url = 'http://yourdomain.com/sitemap-test-5.xml';
// Set the default path sitemap ( url located
$path = $sm->find($url,false);
if(!empty($path)){
    $sm->path = $path;
    $sm->setBlock($url)
        ->unsetLastMod()
        ->update();
}

$url = 'http://yourdomain.com/sitemap-test-4.xml';
// Set the path sitemap
$sm->path = 'sitemap-index.xml';
$sm->setBlock($url)
    ->unsetLastMod()
    ->update();

$sm->path = 'sitemap-index.xml';
$sm->delete('http://yourdomain.com/sitemap-test-3.xml');

$sm->path = 'sitemap-index.xml';
for($i=5;$i<10;$i++){
    $sm->prepareDelete('http://yourdomain.com/sitemap-test-'.$i.'.xml')->enqueue();
}
$sm->save();

$sm->path = 'sitemap-index.xml';
$sm->deleteFile();

// Generate All sitemap index into file sitemap.xml
// Note: You need a cronjob to make this refreshed automatically
$sm->generate('https://yourdomain.com');

// Generate All sitemap 


use \SitemapManager\Sitemap;

$sm = new Sitemap;

// Create blank custom sitemap urlset
$sm->path = 'sitemap-post.xml';
$sm->create();

// Set the first sitemap file
$sm->path = 'sitemap-post.xml';
// Set the last sitemap file (will increment automatically)
$sm->setLastFile();
// Check the url in all sitemap files
$url = 'http://yourdomain.com/test-suka-suka-aja-13';
if(!$sm->find($url)){
    $sm->addBlock($url)
        ->addChangeFreq('monthly')
        ->addLastMod(date('Y-m-d'))
        ->addPriority(0.9)
        ->save();
}

$sm->path = 'sitemap-post.xml';
for ($i=0;$i<10;$i++){
    $sm->addBlock('http://yourdomain.com/test-suka-suka-aja-'.$i)
        ->addChangeFreq('monthly')
        ->addLastMod(date('Y-m-d'))
        ->addPriority(0.9)
        ->enqueue();
}
$sm->save();

$url = 'http://yourdomain.com/test-suka-suka-aja-7';
// Set the default path sitemap (l located
$path = $sm->find($url,false);
if(!empty($path)){
    $sm->path = $path;
    $sm->setBlock($url)
        ->setChangeFreq('daily')
        ->setLastMod(date('Y-m-d'))
        ->setPriority(0.5)
        ->update();
}

$url = 'http://yourdomain.com/test-suka-suka-aja-7';
// Set the path sitemap
$sm->path = 'sitemap-post.xml';
$sm->setBlock($url)
    ->setChangeFreq('monthly')
    ->setLastMod(date('Y-m-d'))
    ->setPriority(0.9)
    ->update();

$sm->path = 'sitemap-post.xml';
$sm->delete('http://yourdomain.com/test-suka-suka-aja-7');

$sm->path = 'sitemap-post.xml';
for($i=0;$i<10;$i++){
    $sm->prepareDelete('http://yourdomain.com/test-suka-suka-aja-'.$i)->enqueue();
}
$sm->save();