yehchge / gsitemap
generate google sitemap
v1.0.3
2022-09-21 04:08 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-12-20 09:39:05 UTC
README
generate sitemap.xml tool.
Installation
composer require "yehchge/gsitemap"
Basic Usage
Generate a sample sitemap.xml.
<?php declare(strict_types=1); include "vendor/autoload.php"; use yehchge\gsitemap\GSiteMap; // sample sitemap.xml $GSiteMap = new GSiteMap(); $NodeRoot = $GSiteMap->createUrlSet(); $NodeUrl = $GSiteMap->setUrl($NodeRoot); $GSiteMap->setLoc($NodeUrl, "https://www.example.com/"); $GSiteMap->setLastMod($NodeUrl, date('Y-m-d\TH:i:s') . '+00:00'); $GSiteMap->setPriority($NodeUrl, '1'); $NodeUrl = $GSiteMap->setUrl($NodeRoot); $GSiteMap->setLoc($NodeUrl, "https://www.example.com/404.html"); $GSiteMap->setLastMod($NodeUrl, date('Y-m-d\TH:i:s') . '+00:00'); $GSiteMap->setPriority($NodeUrl, '0.8'); // set full path and filename $GSiteMap->saveFile("sitemap.xml");
Generate a sitemapindex.
<?php declare(strict_types=1); include "vendor/autoload.php"; use yehchge\gsitemap\GSiteMap; // sample sitemap.xml $GSiteMap = new GSiteMap(); $NodeRoot = $GSiteMap->createUrlSet(); $NodeUrl = $GSiteMap->setUrl($NodeRoot); $GSiteMap->setLoc($NodeUrl, "https://www.example.com/"); $GSiteMap->setLastMod($NodeUrl, date('Y-m-d\TH:i:s') . '+00:00'); $GSiteMap->setPriority($NodeUrl, '1'); $NodeUrl = $GSiteMap->setUrl($NodeRoot); $GSiteMap->setLoc($NodeUrl, "https://www.example.com/404.html"); $GSiteMap->setLastMod($NodeUrl, date('Y-m-d\TH:i:s') . '+00:00'); $GSiteMap->setPriority($NodeUrl, '0.8'); // set full path and filename $GSiteMap->saveFile("sitemap_1.xml"); // generate sitemap.xml (index) $NodeRoot = $GSiteMap->createIndex(); $NodeSiteMap = $GSiteMap->setSiteMap($NodeRoot); $GSiteMap->setLoc($NodeSiteMap, "https://www.example.com/sitemap_1.xml"); $GSiteMap->setLastMod($NodeSiteMap, date('Y-m-d\TH:i:s') . '+00:00'); // set full path and filename $GSiteMap->saveFile('sitemap.xml');