Hi David,
I couldn't find any threads on using Featured Products, specifically, on the sidebar navigation. I wanted to list some top sellers vertically on the right sidebar, including their titles, images, prices, etc. I thought the featured products might be a practical idea, if possible. Or, even better, is there a way to have a separate type of featured products listed on the sidebar to avoid duplicates on the homepage (aka: avoid same products shown on homepage and sidebar)?
Thanks!
Stacy
Hi Stacy,
Can you check that you uploaded the files as
featuredproducts.php
html/featured.php
(it sounds like featuredproducts.php may be in the /html/ folder if it is not being found...)
Cheers,
David.
It looks like there were a few different problems, but it's working now. There were a couple of tweaks I wanted to make that I couldn't figure out how to do:
1. I removed the heading (like "Top Selling Products") from the featured products for the sidebar, but I couldn't get rid of the colored background for that heading.
2. Is there a way to move the product titles closer to the top of the product image to save vertical space? Also, is there a way to change the order of things for each product -- like, right now they are ordered title, image, starting at price, compare prices link. What if I wanted it to be image, title, starting at price, compare prices link?
Hi David,
One more idea I just thought of... what if I wanted to remove the thumbnail product image from the sidebar featured products? Or, just make the product image smaller (which I know how to do) but make it centered? Right now, if I make it smaller, it's off to the left.
Hi Stacy,
Could you post your html/featuredTop.php (I assume that's the one being referred to) and I'll take a look at it re: the above...
Cheers,
David.
Hi David,
Below is featuredTop.php. But, I think the issue with the colored background for the heading is in the CSS. Because the color is the background for the featured products heading on the index.php page, if I remove it for the sidebar, it will remove it for the index page, as well. I'd like to keep in on the homepage featured products, though.
<?php
$featured_itemsPerRow = 1;
$featured_row = 0;
?>
<div class='featured'>
<table cellspacing='3'>
<tr>
<th colspan='<?php print $featured_itemsPerRow; ?>'></th>
</tr>
<tr>
<?php foreach($featured["products"] as $product): ?>
<td align='center'>
<h4><a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a></h4>
<?php if ($product["image_url"]): ?>
<?php
if (substr($product["image_url"],0,4)=="http")
{
print "<img width='80' src='".$product["image_url"]."' alt='".$product["name"]."' />";
}
else
{
$begin = strpos($product["image_url"],"src=http://");
if ($begin)
{
$begin = $begin + 4;
$end = strpos($product["image_url"],">",$begin);
$src = substr($product["image_url"],$begin,($end-$begin));
print "<img width='80' src='".$src."' alt='".$product["name"]."' />";
}
else
{
print $product["image_url"];
}
}
?>
<?php endif; ?>
<?php if ($config_useInteraction): ?>
<?php endif; ?>
<?php if ($product["numMerchants"] > 1): ?>
<em><?php print translate("from"); ?></em> <strong><?php print $config_currencyHTML.$product["minPrice"]; ?></strong><br />
<span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("Compare Prices"); ?></a></span>
<?php else: ?>
<strong><?php print $config_currencyHTML.$product["price"]; ?></strong><br />
<span class='nobr'><a href='<?php print $product["productHREF"]; ?>'><?php print translate("More Information"); ?></a></span>
<?php endif; ?>
</p>
</td>
<?php
$featured_row++;
if ($featured_row == $featured_itemsPerRow)
{
print "</tr><tr>";
$featured_row = 0;
}
?>
<?php endforeach; ?>
</tr>
</table>
</div>
Hi Stacy,
Ah - that makes sense... There's no reason however that featuredTop can't use a separate class.
In your featuredTop.php, simply replace line 5 with:
<div class='featuredtop'>
...and then in your default.css, copy the whole .featured section; and paste it back into the same file; but renaming .featured to .featuredtop
Then, the featured products display by featuredTop can be styled separated; in particular .featured h4 { ... } in which you can override or change the style as required.
Hope this helps!
Cheers,
David.
Hi Stacy,
The modifications from this thread sounds like it would be very close to what you want - the code required for your site would be:
featuredproducts.php
<?php
unset($featured);
$sql = "SELECT * FROM `".$config_databaseTablePrefix."featured`
WHERE name LIKE '".$featuredproducts_category."/%'
ORDER BY sequence";
if (database_querySelect($sql,$rows))
{
$sqlNames = array();
$sqlCase = "CASE name";
foreach($rows as $featured)
{
$featured["name"] = str_replace($featuredproducts_category."/","",$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 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"] = $config_baseHREF."product/".tapestry_hyphenate($product["name"]).".html";
$featured["products"][$k]["reviewHREF"] = $config_baseHREF."review/".tapestry_hyphenate($product["name"]).".html";
}
else
{
$featured["products"][$k]["productHREF"] = $config_baseHREF."products.php?q=".urlencode($product["name"]);
$featured["products"][$k]["reviewHREF"] = $config_baseHREF."reviews.php?q=".urlencode($product["name"]);
}
}
}
if (isset($featured)) require("html/featured.php");
?>
Then set-up your Featured Products as, for example:
HOME/Home Page Featured Title 1
HOME/Home Page Featured Title 2
TOP/Top Sellers Featured Title 1
TOP/Top Sellers Featured Title 2
etc. etc.
And then in your index.php; replace the existing featured products code with:
$featuredproducts_category = "HOME";
require("featuredproducts.php");
...and in your sidebar, add:
<?php
$featuredproducts_category = "TOP";
require("featuredproducts.php");
?>
However, I'm guessing that the layout that is suitable for the home page is not going to be suitable for the sidebar (horizontal Vs vertical layout); in which case it would be straight forward to create a separate version of html/featured.php for use in the sidebar with the HTML modified as required; simply change featuredproducts.php and replace
if (isset($featured)) require("html/featured.php");
...with:
if ($featuredproducts_category == "TOP")
{
if (isset($featured)) require("html/featuredTop.php");
}
else
{
if (isset($featured)) require("html/featured.php");
}
(where html/featuredTop.php is the alternative version of html/featured.php for display in the sidebar)...
Hope this helps!
Cheers,
David.