I am building a sitemap using the code below. Its url is http://example.com/feed/index.php ... but I would like it to be in a xml format since I get the following error in Webmaster Tools: Your Sitemap does not appear to be in a supported format. Please ensure it meets our Sitemap guidelines and resubmit.
. What is the correct way to accomplish this? I saw someone mention to use mod_rewrite
as a solution. Here: Creating an XML sitemap with PHP
<?php
require_once '../includes/global.inc.php';
$items = $itemTools->getFeedItems();
header("Content-Type: application/xml; charset=ISO-8859-1");
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>Example title</title>
<description>Example description!</description>
<link>http://example.com</link>';
foreach($items as $item)
{
echo '
<item>
<title>'.$item['item_title'].'</title>
<description><![CDATA[
'.$item['item_description'].'
]]></description>
<link>http://www.example.com/item?id='.$item['id'].'</link>
<pubDate>'.$item['add_date'].' GMT</pubDate>
</item>';
}
echo '</channel>
</rss>';
** Edit
Output
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<rss version="2.0">
<script/>
<channel>
<title>Example Site title</title>
<description>Example Site description!</description>
<link>http://example.com</link>
<item>
<title>title</title>
<description>
<![CDATA[ Example description! ]]>
</description>
<link>http://www.example.com/item?id=4</link>
<pubDate>2015-10-12 12:10:04 GMT</pubDate>
</item>
<item>
<title>title</title>
<description>
<![CDATA[ description ]]>
</description>
<link>http://www.example.com/item?id=17</link>
<pubDate>2015-10-06 15:06:24 GMT</pubDate>
</item>
<item>
<title>Title</title>
<description>
<![CDATA[
Description
]]>
</description>
<link>http://www.example.com/item?id=18</link>
<pubDate>2015-10-07 10:40:51 GMT</pubDate>
</item>