Support Forums

Old 02-04-2008, 10:58 PM   #1
Senior Member
 
 
Join Date: Jan 2008
Posts: 124
Rep Power: 9
Soleiltan is on a distinguished road
Question Header for New Listings

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
Soleiltan is offline   Reply With Quote
Old 02-05-2008, 08:59 AM   #2
Coder
 
Join Date: Mar 2006
Posts: 4,567
Rep Power: 111
Lhotch is just really niceLhotch is just really nice
Default

Quote:
Originally Posted by Soleiltan View Post
I want to create a header for the New Listings
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>";
__________________
Larry.
Lhotch is offline   Reply With Quote
Old 02-05-2008, 10:32 AM   #3
68 Evangelist & Developer
 
 
Join Date: Jan 2007
Location: Pennsylvania, USA
Posts: 1,624
Rep Power: 47
Mike-N-Tosh is just really niceMike-N-Tosh is just really nice
Default

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:
<h3 align="center">Some Featured Ads From Our Classifeds Section</h3>
{
custom_listings_horizontal number=4 cols=4 table_attr='width="100%" style="border: 1px solid #663300;"' 
td_attr='width="25%" valign="middle" align="center"'
I did it this way for two reasons:
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
Attached Files
File Type: zip function.custom_listings_horizontal.php.zip (2.1 KB, 1 views)
__________________
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
Mike-N-Tosh is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 08:55 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0