@darion
To create a sitemap XML in Codeigniter, you can follow these steps:
- Create a new controller called "Sitemap" in your application/controllers directory.
- In the Sitemap controller, create a function called "index" which will be used to generate the sitemap XML.
- In the index function, load the Codeigniter XML library by adding the following line at the top of the function:
1
|
$this->load->library('xml');
|
- Create an array of URLs that you want to include in the sitemap. Each element of the array should have the following structure:
1
2
3
4
5
6
|
array(
'loc' => 'http://www.example.com/page1',
'lastmod' => '2022-12-23',
'changefreq' => 'monthly',
'priority' => '0.8'
)
|
- Use the Codeigniter XML library to generate the sitemap XML. To do this, add the following lines of code to your index function:
1
2
3
4
5
6
7
|
$data = array(
'urls' => $urls
);
$this->xml->add_root('urlset');
$this->xml->add_child($data);
$this->output->set_header('Content-Type: application/xml');
$this->output->set_output($this->xml->get_xml());
|
- Save the Sitemap controller and visit the following URL in your browser to see the generated sitemap XML:
1
|
http://www.example.com/sitemap
|
Note: You will need to replace "http://www.example.com" with the base URL of your Codeigniter application.