You are here:  » rss feeds with images


rss feeds with images

Submitted by wilkins on Mon, 2009-11-16 19:13 in

Hi

I was wondering is there a rss feed for products/categories/merchants that have images also.

Thanks

Brent

Submitted by support on Tue, 2009-11-17 09:55

Hi Brent,

As it stands, there aren't any images associated with categories / merchants in the database, unless you have implemented merchant logos which is a popular modification.

Do you already have an RSS script in place, and just want to add images to the feed? If you do; perhaps if you could post the code that you are using I'll work out where to add the image code (they need to be embedded within the description field as HTML - as there isn't actually any image field within the RSS specification)...

Cheers,
David.

Submitted by wilkins on Tue, 2009-11-17 10:58

Hi

Really a feed for the products would be enough, I do not have a feed at present.

Thanks

Brent

Submitted by support on Tue, 2009-11-17 11:07

Hi Brent,

One last question - as the RSS format is not generally used for very large database exports; what control over what is exported do you want to have, and do you want to limit it to, say 10 products etc. (they can be made random).

Perhaps if you could describe your application for the RSS feed that will help me create the most appropriate script for you...

Cheers,
David.

Submitted by wilkins on Tue, 2009-11-17 11:14

Hi David

20 products that could be random would be enough, the idea is for a feed for the site.

Thanks

brent

Submitted by support on Tue, 2009-11-17 11:33

Hi Brent,

Here's a basic random 20 products RSS script with description and image. Save this as rss.php in the main Price Tapestry folder; and then browse to rss.php to generate the feed. Don't forget to update line 2 with your site URL...!

<?php
  $baseURL = "http://www.example.com"; // URL of your site without trailing "/"
  require("includes/common.php");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss version='2.0'>";
  print "<channel>";
  print "<title>RSS Product Export</title>";
  print "<link>".$baseURL.$config_baseHREF."</link>";
  print "<description>RSS Product Export</description>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 20";
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $product)
    {
      print "<item>";
      if ($config_useRewrite)
      {
        $href = "product/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $href = "products.php?q=".urlencode($product["name"]);
      }
      print "<title>".$product["name"]."</title>";
      print "<link>".$baseURL.$config_baseHREF.$href."</link>";
      print "<guid>".$baseURL.$config_baseHREF.$href."</guid>";
      print "<description><![CDATA[";
      print "<img src='".$product["image_url"]."' /><br />";
      print "<p>".$product["description"]."</p>";
      print "]]></description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

Hope this helps!

Cheers,
David.

Submitted by blogmaster2003 on Sun, 2010-04-18 11:22

Hi

i am having an

Internal Server Error

I changed line 2 to my url, could be some chmod i have to do to the rss.php?

Submitted by support on Sun, 2010-04-18 18:40

Hi,

It shouldn't be anything to do with the script itself (of access mode) - I presume other .php are still working correctly on your server?

Cheers,
David.

Submitted by GemViper on Wed, 2010-04-28 03:55

Just a heads up.

The script works great but it only displays items that have been recently pulled to your site, like when someone visits. If none of the pages have been accessed or the feed has displayed all of the items that WERE shown on site it returns no items.

Not a big deal, if your site isn't generating any visitors you have bigger worries :-)

Submitted by suffolk66 on Thu, 2012-01-26 18:39

I'm using the script above to generate an RSS feed but I'm wondering how effective it is with a limit of 20. An RSS that's not limited would probably be too large so I does anyone have advice on:

a. Whether or not to include images;
b. Good RSS usage with a random feed like this that's limited to 20.

I have experience of feeds but not random ones which are limited. As my site's got >4,000 products, a feed that's not limited is not an option.

Submitted by support on Thu, 2012-01-26 18:55

Hi suffolk66 and welcome to the forum!

> a. Whether or not to include images;

Interestingly, the RSS format doesn't specify image as a field specifically - however many RSS feeds (including that which would be generated by the code above) incorporate images as part of the <description> element, where that element is encapsulated within CDATA tags such that it may contain arbitrary HTML, including therefore the <img> tag as part of that content.

> b. Good RSS usage with a random feed like this that's limited to 20...

The concept of RSS as an "export" format isn't particularly well defined as that isn't really the primary purpose of RSS (which is Syndication); examples on the forum however would always include a LIMIT clause to prevent unnecessary overloading of database were such scripts used against a full database. Images is really down to personal preference and the requirements of your proposed requirement for the feed...

So it really depends on the application you have in mind - if you want to export your entire database as RSS for importing into a 3rd party application that can accept an RSS feed then the limit requirement becomes redundant (as the consumer is an application rather than something that is intending to display the RSS feed)...

Cheers,
David.
--
PriceTapestry.com

Submitted by suffolk66 on Fri, 2012-01-27 07:54

Thanks for the help, David. I was intending on using the RSS feed solely for marketing/seo purposes rather than as an export facility. So I'm not sure if it's right to: limit the feed to 20, include images and randomise its output.

However, if i remove the limit then the feed doesn't work so I don't know the best way to proceed.

Submitted by support on Fri, 2012-01-27 09:54

Hi,

Removing the LIMIT clause would actually result in a query against the entire table so it is most likely timing out. The first thing I would suggest would be to add the following line to the very top of the script, immediately after the opening PHP tag:

  set_time_limit(0);

...and also modify the line that generates the SQL as follows:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER GROUP BY name";

If this still times out, let me know and I'll post a modified version that uses an unbuffered query for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by suffolk66 on Fri, 2012-01-27 10:25

Hello David. I've made the changes but it does still time out.

Here is the code for your reference:

<?php
  set_time_limit(0);
  $baseURL = "{link saved}";
  require("includes/common.php");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss version='2.0'>";
  print "<channel>";
  print "<title>XXXXXXXX RSS</title>";
  print "<link>".$baseURL.$config_baseHREF."</link>";
  print "<description>XXXXXXXXX Products</description>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` GROUP BY name";
  $link = mysql_connect($config_databaseServer,$config_databaseUsername,$config_databasePassword);
  mysql_select_db($config_databaseName,$link);
  $result = mysql_unbuffered_query($sql,$link);
  if ($result)
  {
    while($product = mysql_fetch_assoc($result))
    {
      print "<item>";
      if ($config_useRewrite)
      {
        $href = "product/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $href = "products.php?q=".urlencode($product["name"]);
      }
      print "<title>".$product["name"]."</title>";
      print "<link>".$baseURL.$config_baseHREF.$href."</link>";
      print "<guid>".$baseURL.$config_baseHREF.$href."</guid>";
      print "<description><![CDATA[";
      print "<p>".$product["description"]."</p>";
      print "]]></description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

Submitted by support on Fri, 2012-01-27 10:57

Hi,

I've modified the code in your post above to use an unbuffered query which should do the trick.

Cheers,
David.
--
PriceTapestry.com

Submitted by suffolk66 on Fri, 2012-01-27 11:57

Thanks for your help...but no joy with the above code. It produces the wording up to and including 'Description' but no lines appear afterwards.

Submitted by support on Fri, 2012-01-27 12:31

Hi,

Sorry about that - there was an error in the SQL, which should be:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` GROUP BY name";

(corrected in the post above)

It might be worth testing with a LIMIT clause in the first instance, e.g.

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` GROUP BY name LIMIT 5";

...and then once working as required remove the limit the export all products...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by suffolk66 on Fri, 2012-01-27 12:52

It works perfectly with a limit but fails when the LIMIT 20 is removed.

Submitted by support on Fri, 2012-01-27 13:07

Hi,

It sounds like you may be reaching a web server imposed time limit but one thing to try would be to add a flush() call after the header, and after each item has been output in case the timeout is at a proxy server that is waiting for output.

To do this, REPLACE

  print "<description>XXXXXXXXX Products</description>";

...with:

  print "<description>XXXXXXXXX Products</description>";
  flush();

...and REPLACE

      print "</item>";

...with:

      print "</item>";
      flush();

If that doesn't do the trick; do you have command line (SSH) access to your hosting account in order to run the script from the command line?

Cheers,
David.
--
PriceTapestry.com

Submitted by suffolk66 on Fri, 2012-01-27 13:24

Thanks for your efforts. No luck with the amended script and I'm not sure whether or not I have SSH access to my hosting account. I have CPanel?

Submitted by support on Fri, 2012-01-27 13:30

Hi,

If you have command line access it's most likely via SSH and in most cases the same credentials as you would use for FTP. The most popular SSH client for Windows is Putty. The default settings are for SSH, so if you enter your host name (same as you use for FTP) and click Open you may be presented with a terminal window and prompt to Login As:. Enter your FTP username, and then you should be offered the public key for your server and will be asked to accept it (first time only) before being asked for the password.

If that gets you in, the first stage would be to change directory into your site, which is normally the public_html folder (sometimes called www) using

cd public_html

Once there, try running the command:

php rss.php > products.rss

(assuming that you called the script rss.php).

This should send the output to a file called products.rss which you can then request from your website as normal to download.

One thing I would suggest trying first as the delay is most likely to be the GROUPing on a large table, so it might be worth trying as the main SELECT SQL the following:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` GROUP BY name";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Thu, 2016-06-16 11:48

Hi David,

Find this mod interesting.

Tried it out, while it did create the RSS feed, the URLs were not quite right.

We have characters in our product names. For example: Pretty Dress with polka dots - (blue/white)

Normally when the URLs are written on the product page it becomes: Pretty-Dress-with-polka-dots-blue-white

However, with the rss.php script, the URLs come out: Pretty-Dress-with-polka-dots---(blue/white) and throws up our product has moved alert.

EDIT: It's only certain characters that do this.

Anyway to fix this for our setup?

Thanks!

~ Denis

Submitted by support on Thu, 2016-06-16 15:29

Hi Denis,

For the code from above you are using, look for this section:

      if ($config_useRewrite)
      {
        $href = "product/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $href = "products.php?q=".urlencode($product["name"]);
      }

...and REPLACE with:

      if ($config_useRewrite)
      {
        $href = "product/".tapestry_hyphenate($product["normalised_name"]).".html";
      }
      else
      {
        $href = "products.php?q=".urlencode($product["normalised_name"]);
      }

Cheers,
David.
--
PriceTapestry.com

Submitted by Convergence on Thu, 2016-06-16 19:24

Perfect.

Thanks, David!