What are Sitemaps?
sitemaps.org :
Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site.
Web crawlers usually discover pages from links within the site and from other sites. Sitemaps supplement this data to allow crawlers that support Sitemaps to pick up all URLs in the Sitemap and learn about those URLs using the associated metadata. Using the Sitemap protocol does not guarantee that web pages are included in search engines, but provides hints for web crawlers to do a better job of crawling your site.
Sitemap 0.90 is offered under the terms of the Attribution-Share Alike Creative Commons License and has wide adoption, including support from Google, Yahoo!, and Microsoft.
This example is a static XML file. A dynamic site (based on a database) has to create a dynamic Sitemap(generated and updated by a script, not manually).
- <?php
- $writer = new XMLWriter();
- $writer->openURI(‘sitemap.xml’); // save xml file in root dir
- $writer->startDocument(‘1.0’, ‘UTF-8’);
- $writer->setIndent(4);
- $writer->startElement(‘urlset’);
- $writer->writeAttribute(‘xmlns:xsi’, ‘http://www.w3.org/2001/XMLSchema-instance’);
- $writer->writeAttribute(‘xmlns’, ‘http://www.sitemaps.org/schemas/sitemap/0.9’);
- $writer->writeAttribute(‘xsi:schemaLocation’, ‘http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd’);
- //$mains , get your all post from database
- $data=array(‘url’=>“full url”,‘date’=>‘post date’);
- foreach ($data as $list)
- {
- $lin=utf8_encode($list[‘url’]);
- $url_date = date(DATE_W3C, strtotime($list[‘date’]));
- $writer->startElement(‘url’);
- $writer->writeElement(‘loc’, $lin);
- $writer->writeElement(‘lastmod’,trim($url_date));
- $writer->writeElement(‘changefreq’, ‘always’);
- $writer->writeElement(‘priority’, ‘0.8’);
- $writer->endElement();
- }
- $writer->endElement();
- $writer->endDocument();
- ?>