Hi,
I used the mod for Categorised featured products sections (http://www.pricetapestry.com/node/3243) and I want to have a RSS feed for those products on the front page:
I was working on the following code but this returns empty which is logical because it goes to the featured products list which is empty. Is there a way to get the $featuredproducts_categoryRandom categories which are specified in the index.php to show in a RSS feed?
Additional remark: I have some other feeds/categories which I don't want to have in the rss feed.
<?php
require("includes/common.php");
// ** header("Content-Type: text/xml; charset=utf-8"); ** //
// ** header("Content-Disposition: attachment; filename=featured.xml");** //
header("Content-Type: text/xml");
print "<?xml version='1.0' encoding='UTF-8'?>";
print "<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>";
print "<channel>";
print "<title>somename.com</title>";
print "<link>http://www.somename.com/</link>";
print "<description>somename</description>";
print "<atom:link href='http://www.somename.com/rss.php' rel='self' type='application/rss+xml' />";
$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"; */
$sql = "SELECT * 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 "<title>".$row["name"]." ".$row["price"]." EUR</title>";
print "<link>http://www.somename.com".$config_baseHREF.$href."</link>";
print "<guid>http://www.somename.com".$config_baseHREF.$href."</guid>";
print "<description><![CDATA[";
print "<a href='http://www.somename.com".tapestry_buyURL($row)."'>";
print "<img border='0' width='150' src='".trim($row["image_url"])."' />";
print "</a>";
print $row["description"];
print "]]></description>";
print "</item>";
}
}
print "</channel>";
print "</rss>";
?>
What should I do if I have more than one category?
Hi Marco,
Probably easiest to encode directly into the SQL - so in place of the above modification, have a go with:
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category IN ('Category 1','Category 2','Etc') ORDER BY merchant";
Cheers,
David.
--
PriceTapestry.com
Hi, for most categories it worked, but some categories cause the rss to return empty.
What is causing this?
I noticed it at these two categories:
http://dagaanbiedingen.eu/category/Dagaanbiedingen-overig/
http://dagaanbiedingen.eu/category/Dagaanbiedingen-kleding/
Hi Marco,
Make sure not to include the hyphen characters - so for both those categories the WHERE clause would be:
category IN ('Dagaanbiedingen overig','Dagaanbiedingen kleding')
Hope this helps,
Cheers,
David.
--
PriceTapestry.com
I didn't include the hyphens. If I leave out those two categories I get items in the rss, but if I include those two categories the RSS doesn't return any items:
This link is without the two categories:
{link saved}
and this is with the two categories:
{link saved}
Hi Marco,
Could you post the $sql = ... line from rss2.php and I'll take a look...
Cheers,
David.
--
PriceTapestry.com
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category IN ('Dagaanbiedingen top','Dagaanbiedingen top2','Dagaanbiedingen top3', 'Dagaanbiedingen top4', 'Dagaanbiedingen gadgets', 'Dagaanbiedingen vrije tijd', 'Dagaanbiedingen overig', 'Dagaanbiedingen kleding') ORDER BY merchant";
Hi Marco,
That's very strange - nothing looks wrong at all. Can you try with one and then the other to see if there is a particular one that is causing the problem?
If you could also try with a random category that doesn't exist, e.g. 'widgets' as well that might help shed some light...
Cheers,
David.
--
PriceTapestry.com
I guess it is something in the products that causes the rss to break. The products are changed frequently.
One of the two categories (overig) works now:
{link saved}
But one category (kleding) still has problems, it gives:
{link saved}
page contains the following errors:
error on line 25 at column 3462: xmlParseEntityRef: no name
Below is a rendering of the page up to the first error.
And a dummy category doesn't give any problems:
{link saved}
Hi Marco,
Ah - that would imply it's an RSS validation issue rather than an SQL / code issues. I would suggest making the title element CDATA - to do this change the following line in your code:
print "<title>".$row["name"]." ".$row["price"]." EUR</title>";
to:
print "<title><![CDATA[".$row["name"]." ".$row["price"]." EUR]]></title>";
I think that should be it..!
Cheers,
David.
--
PriceTapestry.com
I still get an error:
This page contains the following errors:
error on line 25 at column 3641: xmlParseEntityRef: no name
Below is a rendering of the page up to the first error.
{link saved}
Hi Marco,
Firefox is being tolerant of the error but I checked with the W3C validator and it is reporting an unexpected token in the link element so it's probably best to CDATA both the link and GUID fields using:
print "<link><![CDATA[http://www.somename.com".$config_baseHREF.$href."]]></link>";
print "<guid><![CDATA[http://www.somename.com".$config_baseHREF.$href."]]></guid>";
Hope this helps,
Cheers,
David.
--
PriceTapestry.com
Hi Marco,
It should be close - you'd just need to change the SQL from the standard featured
products select code to the category random verison, so in place of:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured`";
$featuredproducts_categoryRandom = "Category For RSS Here";
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category = '".$featuredproducts_categoryRandom."' ORDER BY merchant";
Simply change "Category For RSS Here" to the required category for the RSS feed...
Cheers,
David.
--
PriceTapestry.com