You are here:  » Product images in the RSS feed?

Support Forum



Product images in the RSS feed?

Submitted by apa on Sat, 2010-10-30 21:14 in

Is there a way to include product images in my RSS feed?

{link saved}

Best,
Anders

Submitted by support on Sun, 2010-10-31 07:29

Hi Anders,

Sure - in your rss.php you should have a line something like this:

      print "<description><![CDATA[".$row["description"]."]]></description>";

....REPLACE that with:

      print "<description><![CDATA[";
      print $row["description"];
      print "<img src='".$row["image_url"]."' />";
      print "]]></description>";

...to include the image to be embedded within the description content. This is how images are generally included in RSS output as there is no specific image field defined within the format.

Cheers,
David.
--
PriceTapestry.com

Submitted by apa on Mon, 2010-11-01 07:34

Hi David,

Thanks for helping out. It didn't make a difference though.

Here is my feed {link saved}

and here is my rss.php code

<?php
  require("includes/common.php");
  header("Content-Disposition: attachment; filename=products.xml");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss>";
  print "<channel>";
  print "<title>Tjek p&aring; prisen - nye b&oslash;ger (RSS feed)</title>";
  print "<link>{link saved}</link>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY id DESC LIMIT 50";
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $row)
    {
      print "<item>";
      if ($config_useRewrite)
      {
        $href = "product/".tapestry_hyphenate($row["name"]).".html";
      }
      else
      {
       $href = "products.php?q=".urlencode($row["name"]);
      }
      print "<pubDate>".date("Y-m-d")."T08:00:00-05:00</pubDate>";
      print "<title>".substr($row["name"],14,150)."</title>";
      print "<link>{link saved}".$config_baseHREF.$href."</link>";
// print "<description>".substr($row["description"],0,500)."</description>";
// Nyt for at inkluderer cover billede
print "<description><![CDATA[";
print $row["description"];
print "<img src='".$row["image_url"]."' />";
print "]]></description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

Hope you can help?

Best,
Anders

Submitted by support on Mon, 2010-11-01 09:28

Hi Anders,

The image code looks fine, but I noticed the current feed is invalid because of non-encoded entities in the <title> field. To fix this, replace this line:

      print "<title>".substr($row["name"],14,150)."</title>";

...with:

      print "<title><![CDATA[".substr($row["name"],14,150)."]]></title>";

...and the feed should then display correctly...

Cheers,
David.
--
PriceTapestry.com

Submitted by apa on Mon, 2010-11-01 09:49

Fantastic - I was gonna ask you about that.

Always the best service from you.

Best,
Anders

Submitted by apa on Mon, 2010-11-01 09:54

Hmm, I am trying to add this feed to HootSuite, but it says "Please enter a valid RSS or Atom feed"

I think it actually accepted it before I made theese changes. Any idea whats wrong?

Submitted by support on Mon, 2010-11-01 09:55

Hi Anders,

Could you try your feed at http://validator.w3.org/feed/ and let me know what is displayed...

Also if you could let me know the feed URL once more (I'll hide it from your post before publishing) I'll take a further look...

Cheers,
David.
--
PriceTapestry.com

Submitted by apa on Mon, 2010-11-01 10:24

Hi David,

The feed URL is {link saved}

This is the result from the validator...

This feed does not validate.
'utf8' codec can't decode bytes in position 955-957: invalid data (maybe a high-bit character?) [help]

line 1, column 38: Missing rss attribute: version [help]
Tjek på pri ...
^
line 1, column 59: XML parsing error: :1:65: undefined entity [help]
Tjek på pri ...
^
In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation.
Your feed appears to be encoded as "UTF-8", but your server is reporting "US-ASCII" [help]

Submitted by support on Mon, 2010-11-01 10:43

Hi Anders,

The following mods should resolve each of those;

> 'utf8' codec can't decode bytes in position 955-957:
> invalid data (maybe a high-bit character?) [help]

Replace each instance of

$row["title"]

...with:

utf8_encode($row["title"])

And each instance of:

$row["description"]

...with:

utf8_encode($row["description"])

> line 1, column 38: Missing rss attribute: version [help]

Replace

  print "<rss>";

...with:

  print "<rss version='2.0'>";

> line 1, column 59: XML parsing error: :1:65: undefined
> entity [help]

I hadn't spotted this before, with the entity in your title! Replace:

  print "<title>Tjek p&aring; prisen - nye b&oslash;ger (RSS feed)</title>";

...with:

  print "<title>Tjek p&amp;aring; prisen - nye b&amp;oslash;ger (RSS feed)</title>";

> Your feed appears to be encoded as "UTF-8", but your
> server is reporting "US-ASCII" [help]

Replace:

  header("Content-Type: text/xml");

with:

  header("Content-Type: text/xml; charset=utf-8;");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by apa on Mon, 2010-11-01 12:35

Great David,

That worked. Only I have no appearences of $row["title"] in rss.php so i changed instances of $row["name"] instead - I assumes that's what you meant?

Very best,
Anders

Submitted by support on Mon, 2010-11-01 13:40

Sorry Anders, yes - that's correct!

Cheers,
David.
--
PriceTapestry.com