Hi David,
I'd like to create a template page where I can list a number of products - for example a 'Top 10 Red Widgets - buyer's guide' page - where I can list 10 product names and have them displayed like in 'Featured Products'.
So, if I can had a template I could create multiple 'Top 10 buyer's guides' for different types of products on my site.
Is this easy to set-up? Been discussed already in a previous thread?
Regards,
Neil
Brilliant :-)
I'll try it out and let you know how I get on.
Many thanks again David,
Neil
Hi Neil,
This should be straight forward; you can create a "featuredcode.php" script that works in the same way as searchcode.php that you may have come across discussed on other threads where people incorporate products from particular searches into additional subject matter pages.
To do this, first create the following script in your main Price Tapestry directory:
featuredcode.php:
<?php
$sqlNames = array();
$sqlCase = "CASE name";
$sequence = 1;
foreach($featuredProducts as $featuredProduct)
{
$sqlNames[] = "'".$featuredProduct."'";
$sqlCase .= " WHEN '".database_safe($featuredProduct)."' THEN ".$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 name IN (".$sqlIn.") GROUP BY name ORDER BY sequence";
database_querySelect($sql,$rows);
$featured["products"] = $rows;
foreach($featured["products"] as $k => $product)
{
if ($config_useRewrite)
{
$featured["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
$featured["products"][$k]["reviewHREF"] = "review/".tapestry_hyphenate($product["name"]).".html";
}
else
{
$featured["products"][$k]["productHREF"] = "products.php?q=".urlencode($product["name"]);
$featured["products"][$k]["reviewHREF"] = "reviews.php?q=".urlencode($product["name"]);
}
}
if (isset($featured)) require("html/featured.php");
?>
Then, wherever you want to use; for example if you are creating your own top10widgets.php page; simply insert the following PHP at the point where you want your chosen products to appear:
<?php
$featured = array();
$featuredProducts = array();
$featuredProducts[] = "Product 1";
$featuredProducts[] = "Product 2";
$featuredProducts[] = "Product 3";
require("featuredcode.php");
?>
Product 1, Product 2 etc. simply need to match exactly the product names you required from the database.
Hope this helps!
Cheers,
David.