68 Classifieds Forums

68 Classifieds Forums (http://www.68classifieds.com/forums/index.php)
-   v3.1 Questions & Support (http://www.68classifieds.com/forums/forumdisplay.php?f=19)
-   -   Showlistings2.tpl.php help (http://www.68classifieds.com/forums/showthread.php?t=1902)

CHRD 11-07-2006 06:51 PM

Showlistings2.tpl.php help
 
Hi I need and bit of help on the showlistings template, Im not to hot on php but Im willing to get to know this script.
Im wanting to use this for a holiday rental site and Im trying to call bits of information from the database, like, advertisers area, city, number of bedrooms and type of property, also have email a friend link for the showlistings page
Thanks
Glenn

Chaslie 11-07-2006 07:11 PM

I take it these will 'all' be 'extra fields' (administration > category > extra fields) ?

CHRD 11-07-2006 07:35 PM

Iv tryed using something like this {$extra.5.value}
and I cant get the email link to call advert ID number

Chaslie 11-07-2006 07:43 PM

Glen,
I still need to know if you are going to use 'extra fields' or not. This is a question.
Quote:

I take it these will 'all' be 'extra fields' (administration > category > extra fields) ?
Alternatively, if you are using the 'additional fileds' that are available for user registration, there is a different way to add these to showlistings2

CHRD 11-07-2006 07:49 PM

yes I was planing to use these fields, but can I adjust the places these fields show up in showlisting.temp.
Also if a member has more than one property in different locations the wrong area will be displayed in the showlistings page

Chaslie 11-07-2006 07:57 PM

For the email a friend link, you have probably used this:

Code:

<a href="javascript:void(0);" onclick="MM_openBrWindow('{$smarty.const.URL}/friendmail.php?vehicle={$listingid}','contact','width=350,height=400')">{$smarty.const.LANG_EMAIL_FRIEND}</a>
To make it pick up the ID, change {$listingid} to {$entry.id}

That works.

You mentioned 'showlisting.temp' - that's a new one on me. Where is that?

CHRD 11-07-2006 08:03 PM

Sorry I mean showlistings2.tpl.php, I think its best to use extra fields for all advert information, because some people have rentals all over the place.
Also that {$entryid} code didnt work for me
thanks for your help

Chaslie 11-07-2006 08:44 PM

Sorry - it should be {$entry.id}

To add the extra fields into showlisting2, go down to Maffo's entries here..... http://www.68classifieds.com/forums/...0048#post10048

If you get stuck, yell out here and we will be able to help you.

This is a great modification.

CHRD 11-08-2006 05:32 AM

Yes please help me, I need to use extra fields on showlistings.tpl.php
only because a lot of people have property in different areas and in different countries.
from what I understand I need to insert this code to display info from extra fields Iv made up for property details

what I need to know is where the code gets inserted and if I need to re-peat code if I call same data more than once.

extra fields that I would like to use in showlistings2.tpl.php are
Location: text input
Sleeps: drop select
Price: text input
state: text input
country:text input
thanks for your help

Chaslie 11-08-2006 05:49 AM

Quote:

extra fields that I would like to use in showlistings2.tpl.php are
Location: text input
Sleeps: drop select
Price: text input
state: text input
country:drop select
Glen,
Please provide the information requested below and please be very specific.

If you say 'extra fields', I will think you are referring to these (administration > categories > extra fields). If you are NOT referring to these, please call any other fields 'additional fields' so that we don't get confused.

1. Which of these above are 'extra fields' and what are their IDs (administration > categories > extra fields ......... the IDs are beside the name of the extra field)

2. Which of these above are fields you have added to the 'user registration' form? I need to know if they are extra, extra2, extra3.

3. Is 'price', 'state' and 'country' using the normal 68 classifieds fields .... or are these additional fields/extra fields?

CHRD 11-08-2006 06:11 AM

I will not be using any of the "User Registration Fields"

these are the 'additional fields' IDs

Location: id - 9, called x1
Sleeps: id - 11, called x1
Type: id - 5, called x1
Price: id - 7, called x1
state: id - 10, called x3
country: id - 8, called x1

is it possible to have
cheap flights to "state, country"

Chaslie 11-08-2006 04:33 PM

Question - whereabouts in 'administrationm' did you add these fields? Please be very specific.

Also, what does 'called x3' mean? .... as in ....'state: id - 10, called x3'

CHRD 11-08-2006 08:24 PM

I made these fields up in /administration/fields.php.
'state: id - 10, called x3', means I would like to use state data 3 times on showlistings2.tpl.php
like for

cheap travel insurace for "state"
cheap car hire in "state"
cheap flight to "state, country"
credit card trasfur
Email A Friend

"called X3" means I would like to insert state info 3 times on the same page

Chaslie 11-08-2006 09:32 PM

Ok - now I understand - these are called 'extra fields'.

Open up the files category.php, searchresults.php and toplistings.php. They are situated in your root directory of the classifieds script.

In these files you will see this:

Code:

//now get the images
Directly above it in each file, add this:

Quote:

//Get custom extra field location
$mafSQL = "SELECT sValue FROM ".PREFIX."products_fields WHERE pID=".$row['id']." AND fID=9 LIMIT 1";
$mafResult=$db->query($mafSQL);
$mafrs=$mafResult->fetch();
$row['mafExtralocation']=$mafrs['sValue'];

//Get custom extra field sleeps
$mafSQL = "SELECT sValue FROM ".PREFIX."products_fields WHERE pID=".$row['id']." AND fID=11 LIMIT 1";
$mafResult=$db->query($mafSQL);
$mafrs=$mafResult->fetch();
$row['mafExtrasleeps']=$mafrs['sValue'];

//Get custom extra field type
$mafSQL = "SELECT sValue FROM ".PREFIX."products_fields WHERE pID=".$row['id']." AND fID=5 LIMIT 1";
$mafResult=$db->query($mafSQL);
$mafrs=$mafResult->fetch();
$row['mafExtratype']=$mafrs['sValue'];

//Get custom extra field price
$mafSQL = "SELECT sValue FROM ".PREFIX."products_fields WHERE pID=".$row['id']." AND fID=7 LIMIT 1";
$mafResult=$db->query($mafSQL);
$mafrs=$mafResult->fetch();
$row['mafExtraprice']=$mafrs['sValue'];

//Get custom extra field state
$mafSQL = "SELECT sValue FROM ".PREFIX."products_fields WHERE pID=".$row['id']." AND fID=10 LIMIT 1";
$mafResult=$db->query($mafSQL);
$mafrs=$mafResult->fetch();
$row['mafExtrastate']=$mafrs['sValue'];

//Get custom extra field country
$mafSQL = "SELECT sValue FROM ".PREFIX."products_fields WHERE pID=".$row['id']." AND fID=8 LIMIT 1";
$mafResult=$db->query($mafSQL);
$mafrs=$mafResult->fetch();
$row['mafExtracountry']=$mafrs['sValue'];

Have highlighted in red (above) what is actually added for each field being used. The code above is for your 6 fields that you identified to be included in showlistings2.


Now open up showlistings2.tpl.php.

Where you wish to have 'location' displayed, add this: {$entry.mafExtralocation}

Where you wish to have 'sleeps' displayed, add this: {$entry.mafExtrasleeps}

Where you wish to have 'type' displayed, add this: {$entry.mafExtratype}

etc, etc.

Let's know how you go. I'm sure many others will use this modification - it's very simple (when you know how) and very powerfull. Thanks to maffo for the help with this one.

CHRD 11-09-2006 09:35 AM

Iv got the designer copy of 68, I need to upgrade or can you do it with out developer copy??

thanks for your help and time, this is a HOT HACK

Maffo 11-09-2006 10:42 AM

An upgrade is the only way im afraid but worth every penny.

Lhotch 11-09-2006 10:42 AM

I have one site ive been working on which is largely informational and I have nearly 70 fields that I want people to be able to see "at a glance" so I wanted them on the showlisting level. What I did was used the following code to grab all the extra fields. It then adds them to the current $row array with a key that equals their fieldname. The $row array is later assigned to $result and passed to the template.

here is my little code snipped to get and pass the extra fields.

Code:

$extra=array();
                $sSQL = "SELECT f.fID,sValue FROM ".PREFIX."products_fields AS p, `".PREFIX."fields` AS f WHERE p.pID='".$row['id']."' AND f.fSeen='Y' AND p.fID=f.fID ORDER BY f.fOrder ASC";
                $eresult=$db->query($sSQL);
                $i=0;
                while ($rs=$eresult->fetch())
                {
                        $sql="SELECT fID,fName,fType FROM `".PREFIX."fields` WHERE fID='".$rs['fID']."' AND fSeen='Y' ORDER BY fOrder ASC";
                        $eresult2=$db->query($sql);
                        $rs2=$eresult2->fetch();
                        $fieldname=str_replace(" ", "_", $rs2['fName']);
                        $row[$fieldname]=$rs['sValue'];
                                   
                } // end while


Maffo 11-09-2006 10:51 AM

Now thats efficiency!

Thats how it should be written when wanting more than one field.

70 extra fields???:confused: :confused:

CHRD 11-09-2006 10:56 AM

Hi Larry, on what pages did you use this code, do I still need the upgrade

Also if I upgrade to the developer 68 what files do I need to save, So I dont loose all the changes Iv made so far

Lhotch 11-09-2006 11:01 AM

Quote:

Originally Posted by Maffo (Post 10127)
Now thats efficiency!

Thats how it should be written when wanting more than one field.

70 extra fields???:confused: :confused:

Ya, its a lot of extra fields but the site is mainly just an informational database. I want people to be able to see and compare and even change the sort order like default at just a glance without having to go into each ad to see all the little details.

Im doing away with the left nav and will be using a DHTML menu across the top, ive just been too busy to redo the layout.


Quote:

Originally Posted by CHRD (Post 10128)
Hi Larry, on what pages did you use this code, do I still need the upgrade

Also if I upgrade to the developer 68 what files do I need to save, So I dont loose all the changes Iv made so far

That is PHP code so would require the developer edition.

It would need to be added to the same 3 files Chaslie mentioned (ie category.php, searchresults.php and toplistings.php)

CHRD 11-09-2006 11:46 AM

Quote:

Originally Posted by Lhotch (Post 10126)
I have one site ive been working on which is largely informational and I have nearly 70 fields that I want people to be able to see "at a glance" so I wanted them on the showlisting level. What I did was used the following code to grab all the extra fields. It then adds them to the current $row array with a key that equals their fieldname. The $row array is later assigned to $result and passed to the template.

here is my little code snipped to get and pass the extra fields.

Code:

$extra=array();
                $sSQL = "SELECT f.fID,sValue FROM ".PREFIX."products_fields AS p, `".PREFIX."fields` AS f WHERE p.pID='".$row['id']."' AND f.fSeen='Y' AND p.fID=f.fID ORDER BY f.fOrder ASC";
                $eresult=$db->query($sSQL);
                $i=0;
                while ($rs=$eresult->fetch())
                {
                        $sql="SELECT fID,fName,fType FROM `".PREFIX."fields` WHERE fID='".$rs['fID']."' AND fSeen='Y' ORDER BY fOrder ASC";
                        $eresult2=$db->query($sql);
                        $rs2=$eresult2->fetch();
                        $fieldname=str_replace(" ", "_", $rs2['fName']);
                        $row[$fieldname]=$rs['sValue'];
                                   
                } // end while


Im lost a bit here, dose your code need to be inserted everytime I call an extra field value and on my showlistings page what code do I insert if my field name is "Property Type" with an ID of 10

CHRD 11-10-2006 11:49 AM

viewlisting.tpl.php
 
What files do I need to edit to implement this code in the viewlisting.tpl.php
I want to call some extra field values more than once on this page

Lhotch 11-10-2006 12:43 PM

Quote:

Originally Posted by CHRD (Post 10132)
Im lost a bit here, dose your code need to be inserted everytime I call an extra field value and on my showlistings page what code do I insert if my field name is "Property Type" with an ID of 10

Ok, lets back up a little and make sure we are on the same page.

php script files have names like "myscript.php"
template files have names like "mytemplate.tpl.php"

script files have the php code in them and do various things then pass variables from from the executing script to the template where they are displayed.

Now, the template that shows us the table with a list of ads is called "showlistings.tpl.php" or alternatively showlistings2.tpl.php. By default this table can only display the default ad fields. These are fields that are predefined. Extra fields that are created via admin and assigned to various categories via the site administration are stored in a separate database table and linked to the ad when an individual ad is viewed.

To display these "extra fields" in one of the showlistings templates we have to modify the php code of the scripts that send veriables to showlistings templates and have them not only collect default ad data but read in the extra fields and assign them to variables so they can be passed to the templates for display.

The first step is to identify what scripts pass data to the showlisting template. The easiest way to do that is to open the template file layout.tpl.php and at the very top of the file add this....

{debug}

save the file, clear the contants of /templates_c folder. Once thats done goto the page you want simply navigate around your site and when you find a page showing you the table where you want extra field data added. When you first hit your site after adding {debug} it will cause a window to popup which will contain valuable information about variables passed from the underlying script to the template being displayed.

Now, if you goto your sites home page, then select your "spain" category, then the "Costa del Sol" subcategory to display the overview of available listings. Now look at the popup debug window.

At the top you should see something like......

included templates & config files (load time in seconds):
layout.tpl.php (0.05427) (total)
categories/subcategories.tpl.php (0.04858)
showlistings2.tpl.php

and just below that......
assigned template variables:
{$SCRIPT_NAME} /category.php


That tells us that when you are viewing the overview of listings in the subcategory "Costa del Sol" under the main category "Spain" that the script doing the work is "category.php" and that there are 3 templates involved in displaying the data provided by the script "category.php".

As we allready have surmised the template showlisting.tpl.php is the one that actually creates the table and displays the various ads available in a given category. But now we need to find out what other scripts may also call it. This is where you would move around your site looking for places where something similar to the table of ads is displayed when we are looking in a cetegory.

You will notice that if we do a search, the resulting page displayed has a similar table of ads and if we look at the debug info we see once again the template showlistings is called.

ncluded templates & config files (load time in seconds):
layout.tpl.php (0.04570) (total)
showlistings2.tpl.php (0.03987)
assigned template variables:
{$SCRIPT_NAME} /searchresults.php

if we look around a little more and select the "top listings" link and check debug we see something like this....

included templates & config files (load time in seconds):
layout.tpl.php (0.04774) (total)
showlistings2.tpl.php (0.04190)
assigned template variables:
{$SCRIPT_NAME} /toplistings.php


Now we know we have 3 php scripts that are responsible for for passing data to the showlistings template.....ie

category.php
searchresults.php
toplistings.php

So we need to modify each one of these files so that they grab the extra field data so it can be passed along to showlistings template. That is where my little chunk of code comes into play.

Are you with me so far?

Maffo 11-10-2006 02:01 PM

Sorry if this is a little off topic here but I notice you are recieving page load times in your debugger. I dont have these and never have had. They would be a fantastic tool for me. Is there way to turn this on?

Lhotch 11-10-2006 03:26 PM

Quote:

Originally Posted by Maffo (Post 10198)
Sorry if this is a little off topic here but I notice you are recieving page load times in your debugger. I dont have these and never have had. They would be a fantastic tool for me. Is there way to turn this on?

Are you rinning on a windows or linux server?

I believe the debug console uses the microtime() function to determine execution time and its only available on operating systems that support the gettimeofday() system call. So if your not seeing it, its likely due to the OS of the server hosting your site.

Maffo 11-10-2006 03:50 PM

Ok, Im running apache on my local test machine (windows xp).

Hmmm.. this would be so useful to me. I will enquire further, thanks Larry:o

Lhotch 11-10-2006 03:53 PM

Quote:

Originally Posted by Maffo (Post 10212)
Ok, Im running apache on my local test machine (windows xp).

Hmmm.. this would be so useful to me. I will enquire further, thanks Larry:o

Apache is the web server I was referring to the operating system of the system, in your case windows. The microtime() function is based on the gettimeofday() system call which I dont believe windows supports. Most unix op systems do though. Personally I avoid windows servers like the plague, nothing but problems.

Maffo 11-10-2006 04:10 PM

Im with you there and all my live sites run on linux, but my laptop runs windows.

CHRD 11-11-2006 08:38 PM

Quote:

Originally Posted by Chaslie (Post 10096)
Ok - now I understand - these are called 'extra fields'.

Open up the files category.php, searchresults.php and toplistings.php. They are situated in your root directory of the classifieds script.

In these files you will see this:

Code:

//now get the images
Directly above it in each file, add this:



Have highlighted in red (above) what is actually added for each field being used. The code above is for your 6 fields that you identified to be included in showlistings2.


Now open up showlistings2.tpl.php.

Where you wish to have 'location' displayed, add this: {$entry.mafExtralocation}

Where you wish to have 'sleeps' displayed, add this: {$entry.mafExtrasleeps}

Where you wish to have 'type' displayed, add this: {$entry.mafExtratype}

etc, etc.

Let's know how you go. I'm sure many others will use this modification - it's very simple (when you know how) and very powerfull. Thanks to maffo for the help with this one.

I love you guys, this hack is the best

CHRD 11-13-2006 06:26 AM

viewlisting.tpl.php
 
Hi Iv got this code working fine, but Im trying to use it in viewlisting.tpl.php
I tryed to insert it into viewlistings.php but it gave me errors

Lhotch 11-13-2006 09:01 AM

Quote:

Originally Posted by CHRD (Post 10259)
Hi Iv got this code working fine, but Im trying to use it in viewlisting.tpl.php
I tryed to insert it into viewlistings.php but it gave me errors

All the extra fields are already passed to the viewlisting template, so im not sure I understand what your goals are.

CHRD 11-13-2006 10:57 AM

Im calling using {$extra.??.value} but for some reason its only working on a few extra fields,
the extra frields Im trying to use are single line text boxes

Lhotch 11-13-2006 11:52 AM

Quote:

Originally Posted by CHRD (Post 10273)
Im calling using {$extra.??.value} but for some reason its only working on a few extra fields,
the extra frields Im trying to use are single line text boxes

Im still not following you. The default behavior of the viewlisting.php script is to gather all of the extra fields that have been defined in admin and linked to the category in question, then query the data in those fields and pass it along to the viewlisting.tpl.php template file. It does this without any additional code added to the script files.

The viewlisting.php file assigns the extra field data to a multidimensional array called extra and the viewlisting.tpl.php file uses the following smarty template code to iterate over the array of arrays (multidimensional array).

Code:

{foreach from=$extra item=extras}
<tr>
        <td><strong>{$extras.title}:</strong></td>
        <td>
        {if isset($extras.value)}
          {foreach key=key item=item from=$extras.value}
                {$item}<br />
          {/foreach}
        {/if}
        </td>
</tr>
{/foreach}

On each iteration or loop through the $extra array it pulls out the field title (ie $extras.title) and places it in a table data cell and then if their is a value associated with the array title its also displayed in a table data cell via $item.

The number of extra fields passed by default behavior can vary from category to category depending on what extra fields you have defined.

When in doubt, use the smarty debug console to see what fields are passed as I mentioned in my above post.

CHRD 11-13-2006 01:45 PM

sorry I dont know what going on the {debug} is not working for me
I get this:
Warning: Smarty error: [in layout.tpl.php line 1]: syntax error: plugin function smarty_function_debug() not found in /home/fhlinux198/c/cheapholidayrentalsdirect.com/user/htdocs/includes/classes/smarty/plugins/function.debug.php (Smarty_Compiler.class.php, line 798) in /home/fhlinux198/c/cheapholidayrentalsdirect.com/user/htdocs/includes/classes/smarty/Smarty.class.php on line 1095

juven14 11-13-2006 02:37 PM

Try uploading your smarty plugin directory again:

includes/classes/smarty/plugins


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

Powered by vBulletin® Version 3.6.3
Copyright ©2000 - 2007, Jelsoft Enterprises Ltd.