A sitemap is a file where you can list the web pages of your site to tell Google and other search engines about the organization of your site content. Search engine web crawlers like Googlebot read this file to more intelligently crawl your site.
Why make an XML Sitemap for Static Files?Let’s first address the “why” of this script: in lots of cases, you’ll have static files, either they’re PDF’s, or static PHP or HTML files that create a site. I want all of those in an XML sitemap for two reasons:
- to tell Google that they’re there;
- to be able to see in Google Webmaster Tools whether they’re all indexed.
Configuring the XML Sitemap PHP scriptOf course this script needs a bit of configuration before it’ll work well. It has the following constant & variables:
The directory to search for files in.
The URL to the Sitemaps directory
Whether or not the script should parse recursively.
An array of all the file types that you wish to include in your XML sitemap.
An array of all the files that should be replace with other URL’s, useful to, for instance, replace ‘index.php’ with an empty string, so it’ll look like just example.com/
An array of all the files to ignore in the XML sitemap, useful for your config.php, for instance
A relative path to the XSL file included in the script from the SITEMAP_DIR_URL location.
The change frequency for files, can be ‘hourly’, ‘daily’, ‘monthly’ or ‘never’.
The priority, a value between 0 and 1, since you can’t differentiate between files, there’s no big harm in setting them all to 1.
Styling the output of our XML Sitemap PHP ScriptOf course, we’ll want our XML Sitemap to look good, as well as work well. For that we use an XSL stylesheet which is included in the download. It makes the XML sitemap look like this:
I’ve added the whole script on Github, so you can play, fork, etc.
Or you could just download the zip.