Codeigniter Generate Dynamic XML Sitemap
Today, We want to share with you PHP Codeigniter Creating Dynamic XML Sitemaps.In this post we will show you codeigniter sitemap xml, hear for codeigniter google sitemap generator we will give you demo and example for implement.In this post, we will learn about How to Create Dynamic Sitemap in PHP Codeigniter? with an example.
PHP Codeigniter Generate Dynamic XML Sitemap Example
Codeigniter Create Dynamic Sitemap using PHP sitemap Example
Step 1: Create Route
codeigniter setting : application/config/routes.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); $route['default_controller'] = 'welcome'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; $route['sitemap\.xml'] = "Sitemap/index";
Step 2: Create Sitemap Controller
Codeigniter Generate Dynamic XML Sitemap Example path_ : application/controllers/Sitemap.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Sitemap extends CI_Controller { /** * here main root Index Page for this controller. * */ public function index() { $this->load->database(); $query = $this->db->get("posts"); $data['posts'] = $query->result(); $this->load->view('sitemap', $data); } }
Step 3: Create XML File
application/views/sitemap.php
<?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> <priority>1.0</priority> <changefreq>daily</changefreq> </url> <!-- Sitemap --> <?php foreach($posts as $post) { ?> <url> <loc><?php echo base_url()."post/".$post->id ?></loc> <priority>0.5</priority> <changefreq>daily</changefreq> </url> <?php } ?> </urlset>
You can run simple on following URL on your Browser:
http://localhost:8000/sitemap.xml
jQuery 15 Powerful Tips and Tricks for Developers and Web Designer
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about PHP Codeigniter Creating Dynamic XML Sitemaps.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.