All Projects → asika32764 → php-sitemap

asika32764 / php-sitemap

Licence: GPL-3.0 license
PHP Simple Sitemap Generator

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-sitemap

express-sitemap-xml
Serve sitemap.xml from a list of URLs in Express
Stars: ✭ 56 (+250%)
Mutual labels:  sitemap, sitemap-generator
jsitemapgenerator
Java sitemap generator. This library generates a web sitemap, can ping Google, generate RSS feed, robots.txt and more with friendly, easy to use Java 8 functional style of programming
Stars: ✭ 38 (+137.5%)
Mutual labels:  sitemap, sitemap-generator
X.Web.Sitemap
Simple sitemap generator for .NET
Stars: ✭ 66 (+312.5%)
Mutual labels:  sitemap, sitemap-generator
grav-plugin-sitemap
Grav Sitemap Plugin
Stars: ✭ 34 (+112.5%)
Mutual labels:  sitemap, sitemap-generator
sitemap-plugin
Sitemap Plugin for Sylius eCommerce platform
Stars: ✭ 68 (+325%)
Mutual labels:  sitemap, sitemap-generator
sitewriter
A rust library to generate sitemaps.
Stars: ✭ 18 (+12.5%)
Mutual labels:  sitemap, sitemap-generator
scrape
Depth controllable Web scraper and Sitemap Generator in Go
Stars: ✭ 19 (+18.75%)
Mutual labels:  sitemap, sitemap-generator
sitemap
A simple sitemap generator for Laravel Framework.
Stars: ✭ 32 (+100%)
Mutual labels:  sitemap, sitemap-generator
Craft Seomatic
SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
Stars: ✭ 135 (+743.75%)
Mutual labels:  sitemap
sitemap-webpack-plugin
Webpack plugin to generate a sitemap.
Stars: ✭ 72 (+350%)
Mutual labels:  sitemap
Craft Sitemap
Craft plugin to generate a sitemap.
Stars: ✭ 105 (+556.25%)
Mutual labels:  sitemap
Go Sitemap Generator
go-sitemap-generator is the easiest way to generate Sitemaps in Go
Stars: ✭ 152 (+850%)
Mutual labels:  sitemap
sitemapper
Fast, stream based XML Sitemap generator in Elixir
Stars: ✭ 32 (+100%)
Mutual labels:  sitemap-generator
Sitemap
PHP XML Sitemap Generation
Stars: ✭ 128 (+700%)
Mutual labels:  sitemap
sitemapper
parses sitemaps for Node.JS
Stars: ✭ 70 (+337.5%)
Mutual labels:  sitemap
Vue Router Sitemap
Generate sitemap.xml by vue-router configuration
Stars: ✭ 102 (+537.5%)
Mutual labels:  sitemap
Laravel Seo Tools
Laravel Seo package for Content writer/admin/web master who do not know programming but want to edit/update SEO tags from dashboard
Stars: ✭ 99 (+518.75%)
Mutual labels:  sitemap
classicpress-seo
Classic SEO is the first SEO plugin built specifically to work with ClassicPress. A fork of Rank Math, the plugin contains many essential SEO tools to help optimize your website.
Stars: ✭ 18 (+12.5%)
Mutual labels:  sitemap
Sitemap
Google sitemap builder for Laravel
Stars: ✭ 243 (+1418.75%)
Mutual labels:  sitemap
Sitemap Generator Cli
Creates an XML-Sitemap by crawling a given site.
Stars: ✭ 214 (+1237.5%)
Mutual labels:  sitemap

PHP Sitemap

PHP Simple Sitemap Generator. Follows the W3C Sitemap Protocol

Installation via Composer

Add this to composer.json require block.

{
    "require": {
        "asika/sitemap": "1.*"
    }
}

Getting Started

Create a sitemap object:

use Asika\Sitemap\Sitemap;

$sitemap = new Sitemap;

Add items to sitemap:

$sitemap->addItem($url);
$sitemap->addItem($url);
$sitemap->addItem($url);

You can add some optional params.

use Asika\Sitemap\ChangeFreq;

$sitemap->addItem($url, '1.0', ChangeFreq::DAILY, '2015-06-07 10:51:20');
$sitemap->addItem($url, '0.7', ChangeFreq::WEEKLY, new \DateTime('2015-06-03 11:24:20'));

The arguments are loc, priority, changefreq and lastmod. See this table:

Params Required Description
loc required URL of the page. This URL must begin with the protocol (such as http) and end with a trailing slash, if your web server requires it. This value must be less than 2,048 characters.
priority optional The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value does not affect how your pages are compared to pages on other sites—it only lets the search engines know which pages you deem most important for the crawlers.
changefreq optional How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page.
lastmod optional The date of last modification of the file. This date should be in W3C Datetime format. This format allows you to omit the time portion, if desired, and use YYYY-MM-DD.

See: http://www.sitemaps.org/protocol.html#xmlTagDefinitions

Render it to XML:

echo $sitemap->toString();

// OR

(string) $sitemap;

This is an example to send it as real sitemap for Google or other search engine:

header('Content-Type: application/xml');

echo $sitemap;

exit();

Output:

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<url>
		<loc>http://sitemap.io</loc>
	</url>
	<url>
		<loc>http://sitemap.io/foo/bar/?flower=sakura&amp;fly=bird</loc>
		<changefreq>daily</changefreq>
		<priority>1.0</priority>
		<lastmod>2015-06-07T10:51:20+02:00</lastmod>
	</url>
</urlset>

Arguments

loc

The URL will be auto escaped. For example, the &, > will convert to &amp;, &gt;.

If you want to escape it yourself, set auto escape off:

$sitemap->setAutoEscape(false);

See: http://www.sitemaps.org/protocol.html#escaping

changefreq

Valid values are:

ChangeFreq::ALWAYS;
ChangeFreq::HOURLY;
ChangeFreq::DAILY;
ChangeFreq::WEEKLY;
ChangeFreq::MONTHLY;
ChangeFreq::YEARLY;
ChangeFreq::NEVER;

The value always should be used to describe documents that change each time they are accessed.

The value never should be used to describe archived URLs.

Please note that the value of this tag is considered a hint and not a command. Even though search engine crawlers may consider this information when making decisions, they may crawl pages marked hourly less frequently than that, and they may crawl pages marked yearly more frequently than that.

Crawlers may periodically crawl pages marked never so that they can handle unexpected changes to those pages.

priority

The default priority of a page is 0.5. Please note that the priority you assign to a page is not likely to influence the position of your URLs in a search engine's result pages. Search engines may use this information when selecting between URLs on the same site, so you can use this tag to increase the likelihood that your most important pages are present in a search index. Also, please note that assigning a high priority to all of the URLs on your site is not likely to help you. Since the priority is relative, it is only used to select between URLs on your site.

lastmod

Your date format will auto convert to W3c Datetime format. for example, if you send a string look like: 2015-06-07 10:51:20, Sitemap object will auto convert it to 2015-06-07T10:51:20+02:00.

You can set the format you want:

$sitemap->setDateFormat(\DateTime::ISO8601);

// OR

$sitemap->setDateFormat('Y-m-d');

Using Sitemap index files (to group multiple sitemap files)

use Asika\Sitemap\SitemapIndex;

$index = new SitemapIndex;

$index->addItem('http://domain.com/sitemap1.xml', $lastmod1);
$index->addItem('http://domain.com/sitemap2.xml', $lastmod2);

echo $index->toString();

Output:

<?xml version="1.0" encoding="utf-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
        <loc>http://domain.com/sitemap1.xml</loc>
        <lastmod>2015-06-07T10:51:20+02:00</lastmod>
    </sitemap>
	<sitemap>
		<loc>http://domain.com/sitemap2.xml</loc>
		<lastmod>2015-06-07T10:51:20+02:00</lastmod>
	</sitemap>
</sitemapindex>

See: http://www.sitemaps.org/protocol.html#index

More

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].