0

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>
Community
  • 1
  • 1
Ciprian
  • 3,066
  • 9
  • 62
  • 98
  • Can you show us the output of your script, or at least a part of it? – Jerodev Oct 16 '15 at 06:31
  • Added output to the question. – Ciprian Oct 16 '15 at 06:42
  • How is the " Here: Creating an XML sitemap with PHP" reference to a different question related to your question? Why do you generate the XML "by hand" (that is concatenating strings) and you're not using an XML library which has been written to create XML in a less error prone way? Why do you expect your sitemap.xml to work when it obviously does not adhere to the sitemap XML standard? Please excuse the many questions back, they hopefully shed some insight where areas are that could lead to your degraded experience with creating XML sitemaps in PHP. – hakre Oct 16 '15 at 07:57
  • XML sitemap standard is here: http://www.sitemaps.org/ <- your XML must match with the requirements given there. There should be also validators available. – hakre Oct 16 '15 at 07:57

0 Answers0