egvolkvolk / smg
Sitemap Generator
dev-main
2024-05-16 15:45 UTC
Requires
- php: > 8
- ext-dom: *
- composer/installers: *
This package is auto-updated.
Last update: 2025-07-16 18:36:54 UTC
README
Hello, tutorial for initializing and using the library to create a sitemap
Initializing
- Open your terminal
- For necessary, install composer php composer install
- Install library SitemapGenerator php composer require egvolkvolk/smg
- Later, library create needed files as vendor, egvolkvolk, e.t.c...
Using
- Create new php-file, for example index.php
- Add require require 'vendor\egvolkvolk\smg\src\SitemapGenerator.php';
- Add site data
- data - list of site pages with parameters
- loc - page address
- lastmod - modified date
- priortity - parsing priority
- changefreq - update frequency
- datatype - file type for generation. Could be array
- directory - path to the file to save
- data - list of site pages with parameters
- Add this code
$sitemapGenerator = new SitemapGenerator();
foreach ($dataTypes as $dataType) {
$sitemapGenerator->convertToDataType($data, $dataType, $directory);
}
My executable php-file
<?php
use src\SitemapGenerator;
require 'vendor\egvolkvolk\smg\src\SitemapGenerator.php';
$data = [
[
'loc' => 'https://pyrobyte.ru/',
'lastmod' => '2024-05-05',
'priority' => '0.9',
'changefreq' => 'weekly',
],
[
'loc' => 'https://pyrobyte.ru/cases',
'lastmod' => '2024-04-03',
'priority' => '0.5',
'changefreq' => 'monthly',
],
[
'loc' => 'https://pyrobyte.ru/career',
'lastmod' => '2024-02-24',
'priority' => '0.3',
'changefreq' => 'yearly',
],
[
'loc' => 'https://pyrobyte.ru/blog',
'lastmod' => '2024-05-07',
'priority' => '0.7',
'changefreq' => 'daily',
],
];
$directory = './upload';
$dataTypes = [
'xml',
'csv',
'json',
];
$sitemapGenerator = new SitemapGenerator();
foreach ($dataTypes as $dataType) {
$sitemapGenerator->convertToDataType($data, $dataType, $directory);
}
Result of the library
CSV
loc;lastmod;priority;changefreq
https://pyrobyte.ru/;2024-05-05;0.9;weekly
https://pyrobyte.ru/cases;2024-04-03;0.5;monthly
https://pyrobyte.ru/career;2024-02-24;0.3;yearly
https://pyrobyte.ru/blog;2024-05-07;0.7;daily
JSON
[
{
"loc": "https://pyrobyte.ru/",
"lastmod": "2024-05-05",
"priority": "0.9",
"changefreq": "weekly"
},
{
"loc": "https://pyrobyte.ru/cases",
"lastmod": "2024-04-03",
"priority": "0.5",
"changefreq": "monthly"
},
{
"loc": "https://pyrobyte.ru/career",
"lastmod": "2024-02-24",
"priority": "0.3",
"changefreq": "yearly"
},
{
"loc": "https://pyrobyte.ru/blog",
"lastmod": "2024-05-07",
"priority": "0.7",
"changefreq": "daily"
}
]
XML
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://pyrobyte.ru/</loc>
<lastmod>2024-05-05</lastmod>
<priority>0.9</priority>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>https://pyrobyte.ru/cases</loc>
<lastmod>2024-04-03</lastmod>
<priority>0.5</priority>
<changefreq>monthly</changefreq>
</url>
<url>
<loc>https://pyrobyte.ru/career</loc>
<lastmod>2024-02-24</lastmod>
<priority>0.3</priority>
<changefreq>yearly</changefreq>
</url>
<url>
<loc>https://pyrobyte.ru/blog</loc>
<lastmod>2024-05-07</lastmod>
<priority>0.7</priority>
<changefreq>daily</changefreq>
</url>
</urlset>