2017 © Pedro PelĆ”ez
 

craft-plugin craft-sitemap

image

groe/craft-sitemap

  • Monday, July 30, 2018
  • by mcacace
  • Repository
  • 3 Watchers
  • 24 Stars
  • 369 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 30 Forks
  • 1 Open issues
  • 13 Versions
  • 20 % Grown

The README.md

NOTE: This is a fork of the currently unmaintained craft-sitemap plugin by @joshuabaker. The original author has not responded to questions regarding his plans for the future of the project. So feel free to use the fork while we (hopefully) merge it back some day., (*1)

Craft Sitemap

A simple plugin for Craft that generates a sitemap.xml based on enabled sections., (*2)

Settings, (*3)

Installation

  1. Copy the sitemap/ folder into craft/plugins/
  2. Go to Settings ā†’ Plugins and click the ā€œInstallā€ button next to ā€œSitemapā€

Usage

Within the plugin settings, check the boxes in the ā€œEnabledā€ column to include them in the sitemap., (*4)

To view the output visit /sitemap.xml., (*5)

Advanced

This plugin exposes various service methods, which can be used to add custom items to the sitemap through the renderSitemap hook. Please read the official ā€˜Hooks and Eventsā€™ documentation, if youā€™re not sure how this works., (*6)

Hooks

renderSitemap

Add a renderSitemap method to your plugin to add items via the various service methods listed below., (*7)

Hereā€™s an example plugin hook method with comments:, (*8)

public function renderSitemap()
{
    // Get an ElementCriteriaModel from the ElementsService
    $criteria = craft()->elements->getCriteria(ElementType::Entry);

    // Specify that we want entries within the ā€˜locationsā€™ section
    $criteria->section = 'locations';

    // Loop through any entries that were found
    foreach ($criteria->find() as $locationEntry)
    {
        // Here weā€™re building a path using the entry slug.
        // This might match a custom route youā€™ve defined that
        // should be included in the sitemap.
        $path = 'cars-for-sale-in-' . $locationEntry->slug;

        // Make sure that weā€™re using a full URL, not just the path.
        $url = UrlHelper::getSiteUrl($path);

        // For the sake of this example, weā€™re setting the $lastmod
        // value to the most recent time the location entry was
        // updated. You can pass any time using the DateTime class.
        $lastmod = $locationEntry->dateUpdated;

        // Add the URL to the sitemap
        craft()->sitemap->addUrl($url, $lastmod, Sitemap_ChangeFrequency::Daily, 0.5);
    }
}

And hereā€™s an example of the resulting element in the sitemap XML:, (*9)

<url>
  <loc>http://example.com/cars-for-sale-in-scotland</loc>
  <lastmod>2015-08-28T15:08:28+00:00</lastmod>
</url>

Service Methods

Thereā€™s several service methods made available to add items to the sitemap., (*10)

addUrl($loc, $lastmod, [$changefreq, [$priority]])

Adds a URL to the sitemap., (*11)

$loc = UrlHelper::getSiteUrl('special/route');
$lastmod = new DateTime('now');
craft()->sitemap->addUrl($loc, $lastmod, Sitemap_ChangeFrequency::Yearly, 0.1);
addElement(BaseElementModel $element, [$changefreq, [$priority, [$currentLocaleOnly, [$alternateUrls]]]])

Adds an element to the sitemap., (*12)

$element = craft()->elements->getElementById(2);
craft()->sitemap->addElement($element, Sitemap_ChangeFrequency::Daily, 1.0);
addSection(SectionModel $section, [$changefreq, [$priority, [$currentLocaleOnly, [$alternateUrls]]]])

Adds all entries in the section to the sitemap., (*13)

$section = craft()->sections->getSectionByHandle('homepage');
craft()->sitemap->addSection($section, Sitemap_ChangeFrequency::Weekly, 1.0);
addCategoryGroup(CategoryGroupModel $categoryGroup, [$changefreq, [$priority, [$currentLocaleOnly, [$alternateUrls]]]])

Adds all categories in the group to the sitemap., (*14)

$group = craft()->categories->getGroupByHandle('news');
craft()->sitemap->addCategoryGroup($group);
getElementUrlForLocale(BaseElementModel $element, $locale)

Gets a element URL for the specified locale. The locale must be enabled., (*15)

echo $element->url;
// http://example.com/en/hello-world

echo craft()->sitemap->getElementUrlForLocale($element, 'fr');
// http://example.com/fr/bonjour-monde
getUrlForLocale($path, $locale)

Gets a URL for the specified locale. The locale must be enabled., (*16)

echo UrlHelper::getSiteUrl('foo/bar');
// http://example.com/en/foo/bar

echo craft()->sitemap->getUrlForLocale('foo/bar', 'fr');
// http://example.com/fr/foo/bar

Helper Classes

Sitemap_ChangeFrequency

Enumeration of valid changefreq values., (*17)

Sitemap_ChangeFrequency::Always
Sitemap_ChangeFrequency::Hourly
Sitemap_ChangeFrequency::Daily
Sitemap_ChangeFrequency::Weekly
Sitemap_ChangeFrequency::Monthly
Sitemap_ChangeFrequency::Yearly
Sitemap_ChangeFrequency::Never

The Versions

30/07 2018

dev-multi-locale-domain-support

dev-multi-locale-domain-support

  Sources   Download

18/04 2018

dev-master

9999999-dev

Craft plugin to generate a sitemap.

  Sources   Download

MPL 2.0

The Requires

 

18/04 2018

v1.2.3

1.2.3.0

Craft plugin to generate a sitemap.

  Sources   Download

MPL 2.0

The Requires

 

18/04 2018

dev-develop

dev-develop

Craft plugin to generate a sitemap.

  Sources   Download

MPL 2.0

The Requires

 

05/03 2018

v1.0.0-alpha.1

1.0.0.0-alpha1

  Sources   Download

05/03 2018

v1.0.0-alpha.2

1.0.0.0-alpha2

  Sources   Download

05/03 2018

v1.0.0-alpha.3

1.0.0.0-alpha3

  Sources   Download

05/03 2018

v1.0.0-alpha.4

1.0.0.0-alpha4

  Sources   Download

05/03 2018

v1.0.0

1.0.0.0

  Sources   Download

18/02 2018

v1.2.2

1.2.2.0

Craft plugin to generate a sitemap.

  Sources   Download

MPL 2.0

The Requires

 

06/02 2018

v1.2.1

1.2.1.0

Craft plugin to generate a sitemap.

  Sources   Download

MPL 2.0

The Requires

 

06/02 2018

v1.2.0

1.2.0.0

Craft plugin to generate a sitemap.

  Sources   Download

MPL 2.0

The Requires

 

11/05 2017

v1.1.0

1.1.0.0

Craft plugin to generate a sitemap.

  Sources   Download

MPL 2.0

The Requires