PHP code example of gimucco / sitemap

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

    

gimucco / sitemap example snippets


use Gimucco\Sitemap\Runner;
use Gimucco\Sitemap\Url;

d.
$sitemaps_folder_path = __DIR__.'/sitemaps/';
// This is the URL corresponding to the path above
$sitemaps_folder_url = 'https://yourdomain.com/sitemaps/';
// Array containing your URLs
$urls = ['https://yourdomain.com/', 'https://yourdomain.com/contacts', 'https://yourdomain.com/signup', 'https://yourdomain.com/login'];

// Starting the Runner
// First parameter is the local path to the folder where Sitemaps will be saved
// Second parameter is the URL to reach the sitemaps
// Third parameter are options, E.g. Verbosity
$_Runner = new Runner($sitemaps_folder_path, $sitemaps_folder_url, [Runner::OPTION_VERBOSE]);
foreach ($urls as $url) {
	// Push the URL to the sitemap
	// First parameter is the URL of the resource you want to add to the sitemap
	// Second parameter is the Date of last update in ISO8601 format
	// Third parameter is  the priority (0.1 to 1)
	// Fourth parameter is the update frequency (e.g. daily)
	$_Runner->pushURL($url, Url::timeNow(), Url::PRIORITY_HIGHEST, Url::FREQ_ALWAYS);
}
// Write Sitemaps and cleanup
$_Runner->end();
// Optional, send Ping to Google to refresh the Sitemap
$_Runner->pingGoogle();

Sitemap::FREQ_ALWAYS; // always
Sitemap::FREQ_HOURLY; // hourly
Sitemap::FREQ_DAILY; // daily
Sitemap::FREQ_WEEKLY; // weekly
Sitemap::FREQ_MONTHLY; // monthly
Sitemap::FREQ_YEARLY; // yearly
Sitemap::FREQ_NEVER ; // never

Sitemap::PRIORITY_HIGHEST; //1;
Sitemap::PRIORITY_HIGHER; //0.9;
Sitemap::PRIORITY_HIGH; //0.7;
Sitemap::PRIORITY_AVERAGE; //0.5;
Sitemap::PRIORITY_LOW; //0.3;
Sitemap::PRIORITY_LOWER; //0.2;
Sitemap::PRIORITY_LOWEST; //0.1;

Url::convertDateToISO8601("2022-03-13 12:34:56");
// Output: 2022-03-13T12:34:56+00:00

Url::convertTimestampToISO8601(1647147559);
// Output: 2022-03-13T04:59:19+00:00

Sitemap::timeNow(); // Now
Sitemap::timeYesterday(); // 24 hours ago
Sitemap::timeOneWeek(); // One week ago {
Sitemap::timeOneMonth(); // One month ago