Status
, (*1)
Sitemap
use rules Sitemaps XML format for the generate sitemap, (*2)
If you use Symfony 2, you could use our sitemap bridge or sitemap bundle!, (*3)
Installation
Sitemap uses Composer, please checkout the composer website for more information., (*4)
The simple following command will install sitemap
into your project. It also add a new
entry in your composer.json
and update the composer.lock
as well., (*5)
composer require fdevs/sitemap
Usage examples:
create your adapter
'ru', '_format' => 'html'],
['_locale' => 'en', '_format' => 'html'],
['_locale' => 'ru', '_format' => 'rss'],
['_locale' => 'en', '_format' => 'rss'],
];
echo $urlset->xmlString($params);
//<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>http://4devs.io/ru</loc><priority>0.7</priority></url></urlset>
//or save sitemap
$urlset->saveFile('/full/path/to/sitemap.xml',$params);
usage SiteMapIndex
use FDevs\Sitemap\Factory\SiteMapIndex;
$index = new SiteMapIndex('http://domain.ltd','/full/path/to/web/dir');
// your params for the uri
$params = [
['_locale' => 'ru', '_format' => 'html'],
['_locale' => 'en', '_format' => 'html'],
];
echo $index->xmlString($params);
//<sitemapindex><sitemap><loc>http://domain.ltd/ru.html.sitemap.xml</loc></sitemap><sitemap><loc>http://domain.ltd/en.html.sitemap.xml</loc></sitemap></sitemapindex>
//or save sitemap
$index->saveFile('/full/path/to/sitemap.xml',$params);
usage Params helper
use FDevs\Sitemap\Util\Params;
$params = Params::prepare(['_locale'=>['ru','en'],'_format'=>['html','rss']])
//output
//$params = [
// ['_locale' => 'ru', '_format' => 'html'],
// ['_locale' => 'en', '_format' => 'html'],
// ['_locale' => 'ru', '_format' => 'rss'],
// ['_locale' => 'en', '_format' => 'rss'],
//];
usage sitemap manager
use FDevs\Sitemap\SitemapManager;
use FDevs\Sitemap\Factory\SiteMapIndex;
use FDevs\Sitemap\Factory\UrlSet;
use FDevs\Sitemap\Util\Params;
$index = new SiteMapIndex('http://domain.ltd','/full/path/to/web/dir');
$urlset = new UrlSet();
$params = Params::prepare(['_locale'=>['ru','en'],'_format'=>['html','xml']])
$manager = new SitemapManager();
$manager
->add($urlset)
->add($index);
$manager->get('index')->xmlString($params);
$manager->get('index')->saveFile('/full/path/to/sitemap.xml',$params);
$manager->get('sitemap')->xmlString($params);
$manager->get('sitemap')->saveFile('/full/path/to/sitemapindex.xml',$params);
Created by 4devs - Check out our blog for more insight into this and other open-source projects we release., (*6)