This problem arose when I started to get tired of manually submitting post URLs to Google Webmaster, and I wanted to create a sitemap generator like the Blogger feature that provides sitemap.xml.
In this case, I am using CodeIgniter. I found some libraries and almost all of them are outdated and full of bugs. So, should I use those libraries? Or is there another more revolutionary way?
Completion
You can use the following code:
controllers/Seo.php
class Seo extends CI_Controller {
function sitemap()
{
$data = "";//select urls from DB to Array
header("Content-Type: text/xml;charset=iso-8859-1");
$this->load->view("sitemap",$data);
}
}
views/sitemap.php
<?= '<?xml version="1.0" encoding="UTF-8" ?>' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc><?= base_url();?></loc>
<priority>1.0</priority>
</url>
<!-- My code is looking quite different, but the principle is similar -->
<?php foreach($data as $url) { ?>
<url>
<loc><?= base_url().$url ?></loc>
<priority>0.5</priority>
</url>
<?php } ?>
</urlset>
add this line of code in config/routes.php
$route['seo/sitemap\.xml'] = "seo/sitemap";
Understand the conceptual code above, and please adjust it to your own case, if you encounter an error, you can easily solve it if you understand the working principle of the code above.
Good luck!