You are here:  » RSS feed for latest product reviews


RSS feed for latest product reviews

Submitted by kempo on Wed, 2010-08-18 13:53 in

Hi David,
Is it possible to create an RSS feed for last 10 or 20 product's comments/reviews?
Cheers
kempo.

Submitted by support on Wed, 2010-08-18 14:05

Hi Kempo,

Sure have a go with this which I've adapted quickly from the Product export RSS script..

<?php
  require("includes/common.php");
  header("Content-Disposition: attachment; filename=reviews.xml");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss>";
  print "<channel>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."reviews` ORDER BY approved DESC LIMIT 10";
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $row)
    {
      print "<item>";
      if ($config_useRewrite)
      {
        $href = "reviews/".tapestry_hyphenate($row["product_name"]).".html";
      }
      else
      {
        $href = "reviews.php?q=".urlencode($row["product_name"]);
      }
      print "<title>".$row["product_name"]."</title>";
      print "<link>http://www.example.com".$config_baseHREF.$href."</link>";
      print "<description>".$row["comments"]."</description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

Don't forget to replace www.example.com with your site's domain name; and you can change the number of results in the feed by adjusting the LIMIT value on line 8...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by kempo on Thu, 2010-08-19 11:52

Thank you David. It works very well after changing the first 10 rows as follows:

  require("includes/common.php");
  //header("Content-Disposition: attachment; filename=reviews.xml");
  //header("Content-Type: text/xml");
  header('Content-Type: application/xml');
  echo '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
  echo '<?xml-stylesheet href="http://www.w3.org/2000/08/w3c-synd/style.css" type="text/css"?>' . "\n";
  echo '<!-- RSS for ' . $config_title . ', generated on ' . date('r') . ' -->' . "\n";
  print "<rss version='0.92'>";

Submitted by moparr360 on Mon, 2016-12-19 18:15

Hello
I am trying to create an RSS feed and having problems. I have created a file names rss.php and uploaded to the root. I get this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on line 5

I used the same info that is displayed in this thread replacing example.com with my site info

Can you help me please

Bobby

Submitted by support on Tue, 2016-12-20 11:48

Hello Bobby,

Something that happens occasionally when copying code from a forum is if your browser has rendered fancy quotes rather than "normal quotes" as fancy quotes are not valid PHP syntax.

That should be all it is, if you're still getting errors, if you could email me the rss.php file that you created I'll check it out for you...

Cheers,
David.
--
PriceTapestry.com