feature listing horizontal table problems
Hi there,
I have the following problem:
The feature listings in my home page (home.tpl) is being displayed anormaly as you should see on the image I have uploaded.
I want to have 4 cols. Everything is ok on the first row but on the second there is more than 4 cells. I don't know where I have to change the code or what to add in home.tpl, css or function.feature_listings_horizontal.php or maybe in another file?
Here is the code at the end of my home.tpl:
<div id="newlistings">
<h2>{$smarty.const.LANG_FEATURED_LISTINGS}</h2>
{feature_listings_horizontal number=20 cols=4 table_attr='width="100%" cellpadding="8" cellspacing="8" style="border: 1px solid #996633;" ' td_attr=' valign="top" align="left" style="border: 1px solid #cc9966; " '}
</div>
and the code of function.feature_listings_horizontal.php:
function smarty_function_feature_listings_horizontal($param s, &$smarty)
{
global $db, $modules;
$Listing = new Listings();
$table_attr = 'border="1"';
$tr_attr = '';
$td_attr = '';
$number=4;
$cols=4;
$rows=3;
$trailpad = ' ';
$vdir = 'down';
$hdir = 'right';
$inner = 'cols';
$show_price='Y';
$owner = '';
$featured = 'Y';
foreach ($params as $_key=>$_value)
{
switch ($_key)
{
case 'number':
case 'cols':
case 'rows':
case 'owner':
$$_key = (int)$_value;
break;
case 'table_attr':
case 'img_break':
case 'show_price':
case 'featured':
$$_key = (string)$_value;
break;
case 'tr_attr':
case 'td_attr':
$$_key = $_value;
break;
}
}
$sSQL="SELECT id,title,price FROM ".PREFIX."listings WHERE display = 'Y' AND expiration > NOW()";
if($featured=='Y')
{
$sSQL.=" AND featured = 'Y'";
}
if($owner > 0)
{
$sSQL.=" AND owner=".$owner;
}
$sSQL.=" ORDER BY rand() LIMIT ".$number;
$result=$db->query($sSQL);
$i=0;
while($row=$result->fetch())
{
$imageSQL = "SELECT image FROM ".PREFIX."prodimages WHERE pid=".$row['id']." ORDER BY rank LIMIT 1";
$iResult=$db->query($imageSQL);
$irs=$iResult->fetch();
if($irs['image']<>"")
{
$image="thumbs/small_".$irs['image'];
}
else
{
$image="images/nophoto.gif";
}
$tmp = array(
'id' => $row['id'],
'image'=> $image,
'title'=> $row['title'],
'price'=> FormatCurrency($row['price']),
);
$loop[$i++] = $tmp;
}
$loop_count = count($loop);
if (empty($params['rows']))
{
/* no rows specified */
$rows = ceil($loop_count/$cols);
}
elseif (empty($params['cols']))
{
if (!empty($params['rows']))
{
/* no cols specified, but rows */
$cols = ceil($loop_count/$rows);
}
}
$output = "<table " . $table_attr.">\n";
for ($r=0; $r<$rows; $r++)
{
$output .= "<tr" . smarty_function_html_table_cycle_68('tr', $tr_attr, $c) . ">\n";
$rx = ($vdir == 'down') ? $r*$cols : ($rows-1-$r)*$cols;
for ($c=0; $c<$cols; $c++)
{
$x = ($hdir == 'right') ? $rx+$c : $rx+$cols-1-$c;
if ($inner!='cols') {
/* shuffle x to loop over rows*/
$x = floor($x/$cols) + ($x%$cols)*$rows;
}
if ($x<$loop_count)
{
//format the link
$link = $modules->call_hook('listing_url', $loop[$x]);
if($link == '')
{
$link="viewlisting.php?view=".$loop[$x][id];
}
//start td
$output .= "<td" . smarty_function_html_table_cycle_68('td', $td_attr, $c) . ">";
//start image
$output.="<a href='". $link ."'><img src='".$loop[$x][image]."' border='0' alt='".$loop[$x][title]."' /></a><br />";
//close td
//$output.="</td>";
//new td
//$output .= "<td" . smarty_function_html_table_cycle_68('td', $td_attr, $c) . ">";
//text
$output.=$loop[$x][title] ."<br />";
if($show_price=='Y')
{
$output.= $loop[$x][price];
}
//close td
$output.="</td>\n";
}
else
{
$output .= "<td" . smarty_function_html_table_cycle_68('td', $td_attr, $c) . ">" . $trailpad . "</td>\n";
$output .= "<td" . smarty_function_html_table_cycle_68('td', $td_attr, $c) . ">" . $trailpad . "</td>\n";
}
}
$output .= "</tr>\n";
}
$output .= "</table>\n";
return $output;
}
function smarty_function_html_table_cycle_68($name, $var, $no)
{
if(!is_array($var))
{
$ret = $var;
}
else
{
$ret = $var[$no % count($var)];
}
return ($ret) ? ' '.$ret : '';
}
/* End of file function.feature_listings_horizontal.php */
/* Location: ./upload/plugins/function.feature_listings_horizontal.php */
Thanks for your help
(version 4.1.3 developper default template)
|