You are here:  » RSS feed

Support Forum



RSS feed

Submitted by jonny5 on Tue, 2007-11-13 13:09 in

Hi David , have seen that An RSS feed is possible , but some of my sites would have too many products , is it possible to have a RSS feed that just uses all items in the featured list?

many thanks (also cheers for the answer in the other post , im still looking at that mod)

Submitted by support on Tue, 2007-11-13 13:17

Hi Jonny,

Sure - here's the code from the Creating an rss feed thread modified to use the featured products table instead:

rssFeatured.php

<?php
  require("includes/common.php");
  header("Content-Disposition: attachment; filename=featured.xml");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss>";
  print "<channel>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured`";
  if (database_querySelect($sql,$rows))
  {
    $sqlNames = array();
    foreach($rows as $featured)
    {
      $sqlNames[] = "'".$featured["name"]."'";
    }
    $sqlIn = implode(",",$sqlNames);
    $sql = "SELECT name,description FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";
    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 "<title>".$row["name"]."</title>";
      print "<link>http://www.example.com".$config_baseHREF.$href."</link>";
      print "<description>".$row["description"]."</description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

Cheers,
David.

Submitted by jonny5 on Tue, 2007-11-13 13:20

your good , your real good

Submitted by dflsports on Fri, 2008-02-08 18:43

I have this script working :)

But I was trying to add the image_url, I was going to use [cdata [ code here]]

But the image_url never appears, even if I just put print ".$row["image_url"]." the field is left blank

my code

<?php
  require("includes/common.php");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss>";
  print "<channel>";
  print "<title>Featured Products</title>";
  print "<description>Hockey Equipment</description>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured`";
  if (database_querySelect($sql,$rows))
  {
    $sqlNames = array();
    foreach($rows as $featured)
    {
      $sqlNames[] = "'".$featured["name"]."'";
    }
    $sqlIn = implode(",",$sqlNames);
    $sql = "SELECT name,description FROM `".$config_databaseTablePrefix."products`
WHERE name IN (".$sqlIn.") GROUP BY name";
    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 "<title>".$row["name"]."</title>";
      print "<link>http://www.mysite.com".$config_baseHREF.$href."</link>";
      print "<description>".$row["image_url"]."</description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

Submitted by support on Fri, 2008-02-08 18:45

Hi Don,

The image_url field needs to be added to the SQL as it's not currently included. Where you have:

$sql = "SELECT name,description FROM `".$config_databaseTablePrefix."products`
WHERE name IN (".$sqlIn.") GROUP BY name";

...change this to:

$sql = "SELECT name,description,image_url FROM `".$config_databaseTablePrefix."products`
WHERE name IN (".$sqlIn.") GROUP BY name";

Should do the trick!
Cheers,
David.

Submitted by dflsports on Fri, 2008-02-08 19:26

thanks!