Rice-bashing technology open source project: sitemap-php automatically generate site map

Source: Internet
Author: User

Rice-bashing technology products, the recent SEO site is doing optimization, which is one of the sub needs of research to achieve the site map (sitemap.xml)

Encapsulation simplifies many functional modules and is now shared, and the source code can be downloaded from the GitHub, with a simple example.


Github Open source Web site : sitemap-php



What is sitemap-php?

Sitemap-php is a lightweight, simple and quick to generate the site map of the Open source project, by Beijing Rice-bashing Technology Co., Ltd. (mimvp.com) development and sharing.

Through a simple configuration definition, a function createsitemap (), can automatically generate Sitemap.xml, sitemap.html and other site map files,

Automatically generated XML, HTML files, support Google, Bing, Baidu and other mainstream search engines included.

Fast and lightweight class for generating Google sitemap XML files and index of sitemap files.

Written on the PHP and uses XMLWriter extension (wrapper for Libxml XMLWriter APIs) for creating XML files. XMLWriter extension is enabled by default in PHP 5 >= 5.1.2.

If you have more than 50000 URLs, it splits items to seperated files. (in benchmarks, 1.000.000 URL is generating in 8 seconds) Example: Sitemap.xml:http://mimvp.com/sitemap.xml sitemap.html:http://mimvp.com/sitemap.html How to use

The Sitemap encapsulates a class that generates Sitemap.xml properties and methods, using very simple, sample code:

function Testsitemap () {
	$sitemap = new Sitemap ("http://mimvp.com");
	
	 $sitemap->additem ('/', ' 1.0 ', ' daily ', ' today ');
	 $sitemap->additem ('/hr.php ', ' 0.8 ', ' monthly ', Time ());
	 $sitemap->additem ('/index.php ', ' 1.0 ', ' daily ', ' June ');
	 $sitemap->additem ('/about.php ', ' 0.8 ', ' monthly ', ' 2017-06-26 ');
	 
	 $sitemap->additem ('/hr2.php ', ' 1.0 ', ' daily ', Time ())->additem ('/index2.php ', ' 1.0 ', ' daily ', ' Today ')-> AddItem ('/about2.php ', ' 0.8 ', ' monthly ', ' June ');
	 
	 $sitemap->endsitemap ();
}
Initializing class objects
$sitemap = new Sitemap ("http://mimvp.com");
Add Item
$sitemap->additem ('/', ' 1.0 ', ' daily ', ' today ');
$sitemap->additem ('/hr.php ', ' 0.8 ', ' monthly ', Time ());
$sitemap->additem ('/index.php ', ' 1.0 ', ' daily ', ' June ');
$sitemap->additem ('/about.php ', ' 0.8 ', ' monthly ', ' 2017-06-26 ');

Or

$sitemap->additem ('/hr2.php ', ' 1.0 ', ' daily ', Time ())->additem ('/index2.php ', ' 1.0 ', ' daily ', ' Today ')-> AddItem ('/about2.php ', ' 0.8 ', ' monthly ', ' June 25 ');
End Document
$sitemap->endsitemap ();
Build Results Sitemap.xml
<?xml version= "1.0" encoding= "UTF-8"?> <urlset xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/ Sitemap.xsd "xmlns=" http://www.sitemaps.org/schemas/sitemap/0.9 "> <url> <loc>http://mimvp.com/< /loc> <priority>1.0</priority> <changefreq>daily</changefreq> <lastmod>
		2017-06-26t00:00:00+08:00</lastmod> </url> <url> <loc>http://mimvp.com/hr.php</loc> <priority>0.8</priority> <changefreq>monthly</changefreq> <lastmod>2017-06-26t20 :16:23+08:00</lastmod> </url> <url> <loc>http://mimvp.com/index.php</loc> < Priority>1.0</priority> <changefreq>daily</changefreq> <lastmod>2017-06-25t00:00:00+ 08:00</lastmod> </url> <url> <loc>http://mimvp.com/about.php</loc> <priority>0.8</priority> <changefreq>monthly</changefreq> <lastmod> 2017-06-26t00:00:00+08:00</lastmod> </url> </urlset>
More functionsSet root domain
$sitemap = new Sitemap ("http://mimvp.com");

You can also modify the initialized domain name to

$sitemap->setdomain (' http://blog.mimvp.com ');
Set save path Sitemap.xml The default is saved in the current directory, or you can set the folder directory, for example: Xmls/sitemap, which means Sitemap.xml is saved in the xmls/directory under the current directory, where the XMLS directory is automatically created. Note: Support Multilevel catalogs
$sitemap->setxmlfile ("Xmls/sitemap");
$sitemap->setxmlfile ("Xmls/mimvp/sitemap");
Set whether more headers
$sitemap->setischemamore (TRUE);

If set to True, the Sitemap.xml file header adds some header information:

Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" 	
Get the currently written sitemap file
$sitemap->getcurrxmlfilefullpath ();
Advanced FunctionsSpecify the include file to/start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.