Generate a sitemap or sitemap index file for your web application with the CodeIgniter PHP framework. This CodeIgniter model quickly enables you to generate a valid SEO-friendly sitemap file for you web application and/or website. An XML sitemap file helps crawlers of search engines to easily navigate and browse through your website and understand the structure of the different urls.
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.
Read more about the Sitemap protocol on sitemaps.org.
Copy the files in the application folder into your CodeIgniter application folder. This includes the model file and an example controller file. Follow the instructions below on how to use the model in your own controller.The model is designed to be called and controlled by a CodeIgniter controller. The model does not create and save an actual XML-file to be saved on the disk. Rather, it generates a valid XML-file upon each request and directly serves it to the controller and thus the client browser.
This means that two examples of sitemap files to submit to search engines could look like the following urls:
http://www.example.com/index.php/sitemap/general
http://www.example.com/index.php/sitemap/articles
$this->load->model('sitemapmodel');
$this->sitemapmodel->add('http://www.example.com/contact', '2015-11-02', 'monthly', 0.9);
This function checks for the validity of the item on two points:
- The value of the parameter changefreq must be one of the following options:
- always
- hourly
- daily
- weekly
- monthly
- yearly
- never
- The value of the parameter priority must be a value between 0 and 1
If any of the checks fail, an error is triggered by the model.
When you have inserted all the items in the sitemap, you can call the SEO-friendly valid XML-code by calling a simple line of code:$this->sitemapmodel->output();
$this->sitemapmodel->output('sitemapindex');
$this->sitemapmodel->clear();