Categorised featured products sections?
Submitted by macnpaul on Sun, 2010-01-24 16:53.Price Tapestry
I read that you could have multiple rows of featured products, what I was wondering is if you could have different categories for each row?
Video games seems like an obvious example - how would you have one row of featured PS3 games and then below that have a row of featured XBOX games (with headings above each row)?
Thanks,
Paul
Thanks David, managed to get that working.
Hi Paul,
There is quite a neat and straight-forward mod to do this. What it involves is simply pre-fixing each of your Featured Products within the admin area with a "category" name followed by a "/", for example:
PS3/Guitar Hero
PS3/Burnout Paradise City
XBOX/Rock Band
XBOX/Vandal Hearts
etc.
Then, what I would do is extract the Featured Products code from index.php and place it into its own file, so that you then just need to set a category variable, generate any section title you want within the index, and call featuredproducts.php for each section.
To do this, create a new file as follows:
featuredproducts.php
<?phpunset($featured);
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY sequence";
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
$sqlCase = "CASE normalised_name";
foreach($rows as $featured)
{
$featured["name"] = str_replace($featuredproducts_category."/","",$featured["name"]);
$featured["name"] = tapestry_normalise($featured["name"]);
$sqlNames[] = "'".$featured["name"]."'";
$sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
}
$sqlCase .= " END AS sequence";
$sqlIn = implode(",",$sqlNames);
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
database_querySelect($sql,$rows);
$featured["products"] = $rows;
foreach($featured["products"] as $k => $product)
{
if ($config_useRewrite)
{
$featured["products"][$k]["productHREF"] = $config_baseHREF."product/".tapestry_hyphenate($product["normalised_name"]).".html";
$featured["products"][$k]["reviewHREF"] = $config_baseHREF."review/".tapestry_hyphenate($product["normalised_name"]).".html";
}
else
{
$featured["products"][$k]["productHREF"] = $config_baseHREF."products.php?q=".urlencode($product["normalised_name"]);
$featured["products"][$k]["reviewHREF"] = $config_baseHREF."reviews.php?q=".urlencode($product["normalised_name"]);
}
}
}
if (isset($featured)) require("html/featured.php");
?>
Then, simply remove the equivalent code from index.php - let me know if you're not sure what to remove - but it's basically everything from the $sql line to SELECT featured products, down to the line containing require("html/featured.php") - and REPLACE with the following:
print "<h2>PS3</h2>";$featuredproducts_category = "PS3";
require("featuredproducts.php");
print "<h2>XBOX</h2>";
$featuredproducts_category = "XBOX";
require("featuredproducts.php");
Hope this helps!
Cheers,
David.