Here is the exact code we are using.
Home.tpl.php template file:
Code:
<table cellpadding="0" cellspacing="0" class="tableborder">
<tr>
<th width="33%">Most Popular</th>
<th width="33%">Newest Listings</th>
<th width="33%">Highest Rated</th>
</tr>
<tr>
<td valign="top" style="border-right: 1px solid #ccc;">{most_viewed number=5}</td>
<td valign="top" style="border-right: 1px solid #ccc;">{new_listings number=5}</td>
<td valign="top">{highest_rated number=5}</td>
</tr>
</table>
includes/classes/smarty/plugins/function.highest_rated.php
PHP Code:
<?php
/***********************************************************************
| 68 Classifieds developed by 68 Designs, LLC.
|-----------------------------------------------------------------------
| All source code & content (c) Copyright 2005, 68 Designs LLC
| unless specifically noted otherwise.
|
|The contents of this file are protect under law as the intellectual property
| of 68 Designs, LLC. Any use, reproduction, disclosure or copying
| of any kind without the express and written permission of 68 Designs, LLC is forbidden.
|
| Author $Author: Eric $ (68 Classifieds)
| Version $Revision: 1.1 $
| Updated: $Date: 2006/03/14 16:08:04 $
| ______________________________________________________________________
| http://www.68classifieds.com http://www.68designs.com/
***********************************************************************/
function smarty_function_highest_rated($params, &$smarty)
{
global $db;
$number=4;
foreach ($params as $_key=>$_value)
{
switch ($_key)
{
case 'number':
$$_key = (int)$_value;
break;
}
}
$sSQL="SELECT lid, p.title, ROUND(AVG(score)) AS rank FROM ".PREFIX."rating LEFT JOIN ".PREFIX."products AS p ON lid=p.id WHERE approved='Y' AND p.expiration > NOW() AND p.display = 'Y' GROUP BY lid ORDER BY rank";
$result2=$db->query($sSQL);
$output="<ol>";
while($row=$result2->fetch())
{
//echo $row['lid'] .' '. $row['rank'];
$output.='<li><a href="viewlisting.php?view='.$row['lid'].'">'.$row['title'].'</a>';
$output.='<br />'.$row['rank'].' out of 5 stars.</li>';
}
$output.="</ol>";
return $output;
}
?>
includes/classes/smarty/plugins/function.most_viewed.php
PHP Code:
<?php
/***********************************************************************
| 68 Classifieds developed by 68 Designs, LLC.
|-----------------------------------------------------------------------
| All source code & content (c) Copyright 2005, 68 Designs LLC
| unless specifically noted otherwise.
|
|The contents of this file are protect under law as the intellectual property
| of 68 Designs, LLC. Any use, reproduction, disclosure or copying
| of any kind without the express and written permission of 68 Designs, LLC is forbidden.
|
| Author $Author: Eric $ (68 Classifieds)
| Version $Revision: 1.1 $
| Updated: $Date: 2006/03/14 16:08:04 $
| ______________________________________________________________________
| http://www.68classifieds.com http://www.68designs.com/
***********************************************************************/
function smarty_function_most_viewed($params, &$smarty)
{
global $db;
$number=4;
foreach ($params as $_key=>$_value)
{
switch ($_key)
{
case 'number':
$$_key = (int)$_value;
break;
}
}
$sSQL="SELECT p.id, p.title, p.section, p.description, p.hitcount, c.name FROM ".PREFIX."products AS p LEFT JOIN ".PREFIX."categories AS c ON p.section=c.id WHERE p.expiration > NOW() AND p.display = 'Y' ORDER BY hitcount DESC LIMIT ". $number;
$result=$db->query($sSQL);
$i=0;
$output="<ol>";
while($row=$result->fetch())
{
$output.='<li><a href="viewlisting.php?view='.$row['id'].'">'.$row['title'].'</a>';
$output.='<br />'.$row['hitcount'].' Views</li>';
//$output.='</li>';
}
$output.="</ol>";
return $output;
}
?>
includes/classes/smarty/plugins/function.new_listings.php
PHP Code:
<?php
/************************************************** *********************
| 68 Classifieds developed by 68 Designs, LLC.
|-----------------------------------------------------------------------
| All source code & content (c) Copyright 2005, 68 Designs LLC
| unless specifically noted otherwise.
|
|The contents of this file are protect under law as the intellectual property
| of 68 Designs, LLC. Any use, reproduction, disclosure or copying
| of any kind without the express and written permission of 68 Designs, LLC is forbidden.
|
| Author $Author: Eric $ (68 Classifieds)
| Version $Revision: 1.1 $
| Updated: $Date: 2006/03/14 16:08:04 $
| __________________________________________________ ____________________
| http://www.68classifieds.com http://www.68designs.com/
************************************************** *********************/
/**
* Include the {@link shared.make_timestamp.php} plugin
*/
function smarty_function_new_listings($params, &$smarty)
{
global $db;
require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
$number=4;
foreach ($params as $_key=>$_value)
{
switch ($_key)
{
case 'number':
$$_key = (int)$_value;
break;
}
}
$sSQL="SELECT p.id, p.owner, p.title, p.featured, p.section, p.description, p.price, p.dateadded, p.expiration, p.pHighlighted, p.pBold, u.state, u.city, u.country FROM ".PREFIX."products AS p LEFT JOIN ".PREFIX."users AS u ON p.owner = u.id WHERE p.expiration > NOW() AND p.display = 'Y' ORDER BY p.dateadded DESC LIMIT ". $number;
$result=$db->query($sSQL);
$i=0;
$output="<ol>";
while($row=$result->fetch())
{
$output.='<li><a href="viewlisting.php?view='.$row['id'].'">'.$row['title'].'</a>';
$output.='<br />'.new_listings_date_format($row['dateadded']).'</li>';
//$output.='</li>';
}
$output.="</ol>";
return $output;
}
function new_listings_date_format($string, $format="%b %e, %Y", $default_date=null)
{
if (substr(PHP_OS,0,3) == 'WIN') {
$_win_from = array ('%e', '%T', '%D');
$_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y');
$format = str_replace($_win_from, $_win_to, $format);
}
if($string != '') {
return strftime($format, smarty_make_timestamp($string));
} elseif (isset($default_date) && $default_date != '') {
return strftime($format, smarty_make_timestamp($default_date));
} else {
return;
}
}
?>