Skip to content
This repository has been archived by the owner on Sep 17, 2018. It is now read-only.
Mario Bašić edited this page Jul 5, 2017 · 12 revisions

There are 2 main classes in Bard.

If you have ever seen how a sitemap in xml looks like you will know how to use those classes just by looking at their names, but if it still not clear let me explain.

  1. UrlSet - If you want to create a sitemap (Sitemap is a set of URLs) use this class
  2. SitemapIndex - If you want to create a sitemap index (Sitemap index is a set of sitemaps) use this class

Creating a Sitemap

UrlSet has a method called addUrl and with that method you can add URLs to the set of URLs in the UrlSet class. Each URL added is a instance of class Url and it has its own methods and properties with which you can interact.

use Laravelista\Bard\UrlSet;
use Sabre\Xml\Writer;
use Carbon\Carbon;

$sitemap = new UrlSet(new Writer);

$sitemap->addUrl('http://domain.com')
    ->setPriority(1.0)
    ->setChangeFrequency('always')
    ->addTranslation('hr', 'http://domain.com/hr');

$sitemap->addUrl('http://domain.com/contact')
    ->setPriority(0.8)
    ->setChangeFrequency('hourly')
    ->setLastModification(Carbon::now())
    ->addTranslation('hr', 'http://domain.com/hr/contact');

$sitemap->render()->send();

Creating a Sitemap Index

SitemapIndex has a method addSitemap and with that method you can add Sitemaps to the set of Sitemaps in the SitemapIndex class. Each Sitemap added is a instance of class Sitemap and it has its own methods and properties with which you can interact.

use Laravelista\Bard\SitemapIndex;
use Sabre\Xml\Writer;
use Carbon\Carbon;

$sitemapIndex = new SitemapIndex(new Writer);

$sitemapIndex->addSitemap('http://acme.me/sitemap-tags.xml');

$sitemapIndex->addSitemap('http://acme.me/sitemap-events.xml')
    ->setLastModification(Carbon::now());

$sitemapIndex->render()->send();
Clone this wiki locally