Support forum login

©2006-2012 IAAI Software

Contact Us Privacy Policy

RSS feed for latest product reviews

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

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'>";