Random rss feeds for brands,categories and merchants
Hi David
Recently you made me a rss feed for the whole list that was random and could vary the number of listings. This works great and has been very useful. I now want to be more specific and would like feeds for merchants categories and brands, would this be possible.
Thanks
Brent
hi David
This is the code you gave me for products, what I want is just products from a particular merchant, brand, category if that is possible.
Thanks
Brent
<?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>";
?>Hi Brent,
Sure; the following script will just show random products if called as normal, but you can now also add the parameters merchant,category or brand to the URL to limit to that selected item, for example:
rss.php?merchant=Acme
rss.php?category=Electronics
rss.php?brand=Sony(use + in place of spaces in a 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>";
if ($_GET["merchant"]) $where = " WHERE merchant='".database_safe($_GET["merchant"])."' ";
elseif if ($_GET["category"]) $where = " WHERE category='".database_safe($_GET["category"])."' ";
elseif if ($_GET["brand"]) $where = " WHERE brand='".database_safe($_GET["brand"])."' ";
else $where = "";
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ".$where." 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>";
?>Cheers,
David.
Hi
Just come to use this rss and I am getting the following error
Parse error: syntax error, unexpected T_IF, expecting '(' in /home/utoday/public_html/rss.php on line 12
Thanks
Brent
Hi Brent,
Change that block (starting at line 12) to:
if ($_GET["merchant"]) { $where = " WHERE merchant='".database_safe($_GET["merchant"])."' "; }
elseif ($_GET["category"]) { $where = " WHERE category='".database_safe($_GET["category"])."' "; }
elseif ($_GET["brand"]) { $where = " WHERE brand='".database_safe($_GET["brand"])."' "; }
else { $where = ""; }That should be all it is...
Cheers,
David.
Hello Brent,
Sure - could you perhaps post the script that you have so far and I'll base it on that (perhaps adding a "q" parameter) so that you don't require multiple scripts...
Cheers,
David.