• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best Way To Add Sitemap

#3
Here is how I do it:

Before Starting here are some variables and considerations for this specific topic:
- I only have one dynamic pages called blog
- I have a few static pages

Step 1: Controller
I create a controller usually calling it seo.php
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Class 
Seo extends CI_Controller {

 
   function sitemap()
 
   {
        
$this->load->model('blog_model');
        
$data['items'] = $this->blog_model->GetBlog(array(),'slug, created_on, tags');
 
       header("Content-Type: text/xml;charset=iso-8859-1");
 
       $this->load->view("sitemap",$data);
 
   }


Step 2: View
PHP Code:
<?php echo '<?xml version="1.0" encoding="UTF-8" ?>' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc><?php echo base_url();?></loc> 
        <changefreq>weekly</changefreq>
        <priority>1.0</priority>
    </url>
    <?php foreach($items as $item) { ?>
    <url>
        <loc><?php echo base_url().'post/'.$item->slug ?></loc>
        <priority>0.5</priority>
    </url>
    <?php ?>
    <url>
        <loc>http://www.examplesite.com/static-content</loc>
        <priority>0.5</priority>
    </url>
</urlset> 

Step 3: Route (config/routes.php)
In this step I just make sitemap.php be read as sitemap.xml
PHP Code:
$route['seo/sitemap\.xml'] = "seo/sitemap"
Reply


Messages In This Thread
Best Way To Add Sitemap - by bradm - 07-09-2015, 09:06 PM
RE: Best Way To Add Sitemap - by ivantcholakov - 07-10-2015, 06:28 AM
RE: Best Way To Add Sitemap - by edoramedia - 07-12-2015, 10:59 PM
RE: Best Way To Add Sitemap - by arma7x - 07-13-2015, 12:24 AM
RE: Best Way To Add Sitemap - by fcodebue - 12-05-2016, 12:25 PM
RE: Best Way To Add Sitemap - by cartalot - 12-05-2016, 05:27 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.