maxence / sitemap-generator
Little library to automate generation of sitemaps in xml
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/maxence/sitemap-generator
Requires
- php: >= 7.0.0
This package is auto-updated.
Last update: 2020-08-29 06:53:51 UTC
README
Installation
Composer
Install the composer package by running the following command:
composer require maxence/sitemap-generator
Manual
- Download the "Source code" from the latest release
- Include
SitemapGen.php
Example
Add URL to the sitemap
For this example, we suppose the sitemap contain :
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> </urlset>
PHP
$path = path_to_sitemap.xml; $sitemap = new SitemapGen($path); $sitemap->add('htt://example.com/article/eat-frogs', time(), 'never', 1.0);
Result
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://example.com/article/eat-frogs</loc> <lastmod>2018-06-14</lastmod> <changefreq>never</changefreq> <priority>1</priority> </url> </urlset>
Delete URL to the sitemap
For this example, we suppose the sitemap contain the previous result.
PHP
$path = path_to_sitemap.xml; $sitemap = new SitemapGen($path); $sitemap->delete('htt://example.com/article/eat-frogs');
Result
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> </urlset>
Functions
As you see in the example part, this package propose 2 functions ->add() and ->delete()
-
->add(): This function needs 4 parameters, these 4 parameters are the important informations to use in sitemaps, for more information, go to the sitemap doc.- url
- lastUpdate
- frequency
- priority
-
->delete: This function needs 1 parameters- url