You are here

public function Simplesitemap::get_sitemap in Simple XML sitemap 8

Returns the whole sitemap, a requested sitemap chunk, or the sitemap index file.

Parameters

int $sitemap_id:

Return value

string $sitemap If no sitemap id provided, either a sitemap index is returned, or the whole sitemap, if the amount of links does not exceed the max links setting. If a sitemap id is provided, a sitemap chunk is returned.

File

src/Simplesitemap.php, line 147
Contains \Drupal\simplesitemap\Simplesitemap.

Class

Simplesitemap
Simplesitemap class.

Namespace

Drupal\simplesitemap

Code

public function get_sitemap($sitemap_id = NULL) {
  if (empty($this->sitemap)) {
    $this
      ->generate_sitemap();
  }
  if (is_null($sitemap_id) || !isset($this->sitemap[$sitemap_id])) {

    // Return sitemap index, if there are multiple sitemap chunks.
    if (count($this->sitemap) > 1) {
      return $this
        ->get_sitemap_index();
    }
    else {
      return $this->sitemap[0]->sitemap_string;
    }
  }
  else {
    return $this->sitemap[$sitemap_id]->sitemap_string;
  }
}