is it possible to add more featured product pages , so if you clicked electrical you would get electrical featured items , guess you would need to add another featured section in the admin for each featured product page.
actutally im sure ive seen a post here somewhere , if anyone knows?
i want the featured.php for the front of the site showing products from all categories (what ever i put in the list to show)
then I want something link a menu link that says special offer CDs , click that link and then you get the CD featureed items that i have enter into a list , then the same for special offer shoes etc
make sense?
Hi Jonny,
Yes - that makes sense. The easiest way to do this is if you're still happy to make use of the existing product categories (e.g. "CD") to filter the featured products based on the selected category.
This way, you can easily make you menu with links to the homepage as follows:
index.php?featured=CD
...and then the Featured Products code section in index.php can be modified as follows:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
foreach($rows as $featured)
{
$sqlNames[] = "'".$featured["name"]."'";
}
$sqlIn = implode(",",$sqlNames);
if ($_GET["featured"])
{
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") AND category='".database_safe($_GET["featured"])."' GROUP BY name";
}
else
{
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";
}
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");
Hope this helps,
Cheers,
David.
ideally , I didnt really want to go the category way as the products to be shown will be very specific and I would want to change what is shown maybe on a daily basis, is this possible?
Hi Johnny,
An alternative in that case is to change the way you specify featured products to indicate a group name as well as the product name. If you save your Featured Products line this:
Group Name:Product Name
for example:
Electronics:Sony DVD1234
Electronics:Panasonic LCD5678
Home:Inflatable Swimming Pool
Home:Qualcast 1234 Lawn Mower
Then, the following code can be used (with the same link mechanism, for example:
index.php?featured=Electronics
...and it will just select products with that group name. Anything that you want when you want to show all products but don't have a specific group name, just use something like "All" - it doesn't matter what you choose because the entire list will be displayed.
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
foreach($rows as $featured)
{
$use = true;
$parts = explode(":",$featured["name"]);
if ($_GET["featured"])
{
$use = ($_GET["featured"]==$parts[0]);
}
if ($use)
{
$sqlNames[] = "'".$parts[1]."'";
}
}
$sqlIn = implode(",",$sqlNames);
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";
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");
Hope this helps,
Cheers,
David.
Hi david , I hope all is well
you done a mod so that all front featured items are now just random from 2 merchants , this now leaves the list of featured items in the admin section unused , is there a way i can still use the list of featured items on another page?
thanks
Hi Jonny,
Sure - you can take the featured products code from index.php and use it wherever you want. This is the block of code you need:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
foreach($rows as $featured)
{
$sqlNames[] = "'".$featured["name"]."'";
}
$sqlIn = implode(",",$sqlNames);
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") GROUP BY name";
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");
Cheers,
David.
hi david , i get the below error???
Fatal error: Call to undefined function: database_queryselect()
Hiya,
That implies that you've added the code to page that doesn't have the Price Tapestry standard includes at the top.
If you add:
require("includes/common.php");
..above where you have included the code then it should work....
Cheers,
David
Hi Johnny,
I presume you want to do this on the category serach pages....? In which case, a very quick way to do it would be to keep the existing Featured Products table, and then modify the featured products code to add a WHERE clause so that it only picks products that are in the current category.
When on a category search page, the category is in the variable $parts[1], so something like this would work, added to the bottom of search.php. You would need to make sure that you include the code in the right place, so after the requrie("html/header.php") etc. etc..
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
foreach($rows as $featured)
{
$sqlNames[] = "'".$featured["name"]."'";
}
$sqlIn = implode(",",$sqlNames);
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$sqlIn.") AND category='".database_safe($parts[2])."' GROUP BY name";
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");
This would mean that if you still want to display featured products on the homepage, you would need to make a small modification to limit the number displayed, so where you have:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
...change this to:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence LIMIT 4";
This would limit it to the first 4 products in the featured products table.
Cheers,
David.