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-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


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

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