Git Product home page Git Product logo

codeigniter-sitemap-generator's Introduction

CodeIgniter Sitemap Generator Model

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.

What are sitemaps?

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.

Installation

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.

Usage

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

Load the model

You can load the sitemap model from your CodeIgniter controller with the following line of code:
$this->load->model('sitemapmodel');

Add an item

To add an item to the sitemap, use the following line of code:
$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:

  1. The value of the parameter changefreq must be one of the following options:
    • always
    • hourly
    • daily
    • weekly
    • monthly
    • yearly
    • never
  2. 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.

Generate a sitemap file

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();

Generate a sitemap index file

A sitemap index file is a sitemap pointing to one or more other sitemap files. This helps search engine crawlers to easily understand the diversity of sitemaps that are served by your website. To call a sitemap index file instead of a regular sitemap file, simply add the string 'sitemapindex' as a parameter to the output-function, like this:
$this->sitemapmodel->output('sitemapindex');

Clear the sitemap

If you wish to clear the items in the sitemap, call the following function:
$this->sitemapmodel->clear();

codeigniter-sitemap-generator's People

Contributors

alphabase avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.