|
|
#1 |
|
Senior Member
Join Date: Jan 2008
Posts: 124
Rep Power: 9 ![]() |
I want to create a header for the New Listings Table on the front page.
Here is the Smarty Function Code: Code:
<?php
/**
* smarty_function_new_listings
*
* This function is useful for generating a vertical table of new listings.
*
* All source code & content (c) Copyright 2006, 68 Classifieds
* unless specifically noted otherwise.
*
* @package 68classifieds
* @author Eric Barnes
* @copyright 68 Classifieds
* @link http://www.68classifieds.com
* @$Revision: 1.3 $
* @Updated: $Date: 2006/05/26 13:14:08 $
*/
function smarty_function_new_listings($params, &$smarty)
{
global $db;
$table_attr = 'border="1"';
$tr_attr = '';
$td_attr = '';
$number=4;
$trailpad = ' ';
$img_break = '<br />';
$date_format = '%B %e, %Y %I:%M %p';
foreach ($params as $_key=>$_value)
{
switch ($_key)
{
case 'number':
$$_key = (int)$_value;
break;
case 'table_attr':
case 'img_break':
case 'date_format':
$$_key = (string)$_value;
break;
case 'tr_attr':
case 'td_attr':
$$_key = $_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;
while($row=$result->fetch())
{
$tmp = array(
'id' => $row['id'],
'title'=> $row['title'],
'dateadded'=>$row['dateadded'],
'price'=> FormatCurrency($row['price']),
);
$loop[$i++] = $tmp;
}
$loop_count = count($loop)-1;
$output = "<table " . $table_attr.">\n";
for ($x = 0; $x<= $loop_count; $x++)
{
//opening tr
$output .= "<tr" . smarty_function_html_table_cycle_newlistings('tr', $tr_attr, $c) . ">\n";
//opening td
$output .= "<td" . smarty_function_html_table_cycle_newlistings('td', $td_attr, $c) . ">\n";
//title
if(defined('SEO'))
{
$listing_title=$loop[$x][title];
$listing_title=str_replace(' ', '_', $listing_title);
$listing_title=preg_replace('/\W/e', '', $listing_title);
$output.="<a href='listing/".$loop[$x][id]."/".$listing_title.".html'>".$loop[$x][title]."</a>";
}
else
{
$output.="<a href='viewlisting.php?view=". $loop[$x][id] ."'>".$loop[$x][title]."</a>";
}
$output.="</td>\n";
$output .= "<td" . smarty_function_html_table_cycle_newlistings('td', $td_attr, $c) . ">\n";
//price
$output.=$loop[$x][price];
$output.="</td>\n";
$output .= "<td" . smarty_function_html_table_cycle_newlistings('td', $td_attr, $c) . ">\n";
//date
//$output.=smarty_modifier_date_format($loop[$x][dateadded], $date_format);
//closing td
$output.="</td>\n";
$output .= "</tr>\n";
}
$output .= "</table>\n";
return $output;
}
function smarty_function_html_table_cycle_newlistings($name , $var, $no)
{
if(!is_array($var))
{
$ret = $var;
}
else
{
$ret = $var[$no % count($var)];
}
return ($ret) ? ' '.$ret : '';
}
?>
__________________
~~ Lorren Any advice is always appreciated. ![]() v 3.1.10 Developer; v 4 Developer |
|
|
|
|
|
#2 |
|
Coder
Join Date: Mar 2006
Posts: 4,567
Rep Power: 111 ![]() ![]() |
What this php code does is it queries the database and grabs a set amount of new listings. All of the html markup as well as the data pulled from the database is placed into the variable called $output. Once all the data and html is in thevariable its displayed in the template as a complete populated html table.
The following line is where the opening table tag is placed in the variable $output....... $output = "<table " . $table_attr.">\n"; The variable $loop is an array of data that contains the ads and the following line simply loops over the $loops variable and a table data cell is created and populated for each ad. The following line is the tart of the loop and the body of the table is created as the code goes through all the values in the variable $loop. The code below starts the loop. for ($x = 0; $x<= $loop_count; $x++) For a header, depending if your going to use a regular data cell or a table header will ultimately determine what markup you use and since you didnt specify this is just an example. After the opening table html is placed into the $output variable you willneed to add additional HTML for your header. You concatenate data into a variable by using a .= instead of just an = So you could add something like this...... $output.= "<tr><td colspan=8>My header text here</td></tr>"; |
|
|
|
|
|
#3 |
|
68 Evangelist & Developer
Join Date: Jan 2007
Location: Pennsylvania, USA
Posts: 1,624
Rep Power: 47 ![]() ![]() |
Lorren,
I'm not sure exactly what you're after, but what I did for my site was made my own custom smarty template by copying the "function.feature_listings_horizontal.php" and saving the file as "function.custom_listings.horiztonal.php" Then in my content.tpl.php file I added this code to call the function just above the existing table declaration. PHP Code:
1) As my site is a community site and doesn't go into the classifieds when you go there, this promotes the fact that I offer classifieds. (Apparently this is working, because according to my logs approximately 60% of visitors now visit the classifieds section which was previously less than 5%) 2) In my custom function, this is pulling "featured" listings which is an added benefit to those that pay for the featured upgrades. This increases the number of people that pay for the upgrade. Hope that helps, -Mike
__________________
Mike-N-Tosh IndianaPC.org - A community website (v3.1.10 Developer - heavily modified) Sandbox (v3.1.10, v4.0.9, 4.1.3) Visit My blog for tips, tricks, tutorials, reviews for 68 Classifieds as well as my store with Templates, Mods & Docs Web Hosting | Web Design & Development | 68 Classifieds Customizations I am not a 68C employee, just a user and try to help out |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| V4 Changes | Eric Barnes | v4 Questions & Support | 24 | 11-12-2007 01:35 AM |
| Adding a Text Header in Featured Listings | VanWertAds*com | v3.1 Modules & Modifications | 5 | 07-21-2007 04:05 AM |
| Featuered Listings Table Header | brian-bear | v3.1 Questions & Support | 1 | 10-21-2006 05:57 AM |
| Top Listings | sbuell20 | v3.1 Questions & Support | 0 | 09-02-2006 12:11 PM |
| 404 Header For Dead Listings | CB | v3.1 Questions & Support | 7 | 06-15-2006 10:01 AM |