MODIFICATION: Display your extra fields on the showlistings.tpl page

Discussion in 'Modules / Plugins / Modifications' started by cwp, Mar 2, 2008.

  1. cwp Customer

    You must have the developer edition in order to do this modification.

    Put this code somewhere in your includes/classes/kernal/listings.php page. I added it to the
    very end.

    If you have version 4.0 start here. If you have version 4.01, please skip this step and continue with the next one.
    PHP:

    function getExtraField($id,$fieldid)
        {
            global 
    $db;
            
    $sSQL "SELECT sValue FROM ".PREFIX."products_fields WHERE pID='".$id."' AND fID=".$fieldid;
            
    $result=$db->query($sSQL);
            if ( 
    $result->isError() )
            {
                
    trigger_error('Listing::getListing: Unable to fetch listing');
                return 
    false;
            }
            if ( 
    $result->size()>)
            {
                
    $rs=$result->fetch();
                
    $value $rs['sValue'];
            }
            
    $result->freeResult();
            return 
    $value;
        } 
    As a reminder, if you have version 4.01, you will start here:

    Find this:
    PHP:

    $row
    ['status']=$row['display']; 
    Add this right after it:
    PHP:

    $row
    ['extrafield'] = $this->getExtraField($row['id'], 4);
    Keep in mind the number 4 needs to come from the administration extra fields. This is the id of the extra field you want to get.
    Replace the number 4 with your field id which you can get in administration, under extra fields.To add another extra field just it.


    On Showlistings.tpl add this right where you want it to show up:
    Code:
    {$entry.extrafield} 
    
    If you had added multiple, it would be like this, and so on.
    Code:
    {$entry.extrafield2}
    
    Credit goes to suzkaw.
  2. Eric Barnes Guest

    I wanted to follow up on this thread and say that first function is now part of the file. So it will be already included.
  3. cwp Customer

    which version was it added in? And I'll change my post
  4. Eric Barnes Guest

    Sorry forgot to mention that. Starting with v4.0.1 that function is now added.
  5. cwp Customer

    Thanks, I edited the original post with steps for each version.
  6. anna245 Customer

    error on listings.php

    I inserted $row['extrafield'] = getExtraField($row['id'], 4); replacing the "4" with the id number on the listings.php page and when I do a search on the site, the view listings page is blank with this error showing up.

    Fatal error: Call to undefined function: getextrafield() in the listings.php page.

    Any suggestions on how to fix?
  7. Lhotch curmudgeon

    What version of 68C are you running? As Eric stated above, the getextrafield function was added until v4.0.1. Are you running the initial 4.0.0?
  8. Eric Barnes Guest

    It does appear to have an error in the instructions. I have just modified them to be correct. Basically where you have:
    $row['extrafield'] = getExtraField($row['id'], 4);

    Should be:
    $row['extrafield'] = $this->getExtraField($row['id'], 4);

    Also keep in mind the number 4 needs to come from the administration extra fields. This is the id of the extra field you want to get.
  9. cwp Customer


    Thanks for the heads up. I fixed the post.
  10. anna245 Customer

    Thanks! It works now!
  11. bowers01 Genius At Work

    Is there any way to make this work on designer?
    Cheers
  12. forumosa Customer

    What about sorting?

    What about using the extra fields in the showlistings.tpl and sorting with them?

    For example, many of the people who use my classifieds post national ads, so the CITY field will show where their office is, but they may post 3 Job Listings in 3 different cities. I can easily create a JOBCITY field, but I will want the category listings to not only show JOBCITY but allow visitors to sort by JOBCITY
  13. forumosa Customer

    OK, scratch that idea

    It just occurred to me that the business address fields were added to 68c for the reasons I've described above - to distinguish sellers' cities from their ads locations

    Oops
  14. forumosa Customer

    It still might be helpful to know how to do this for other fields (not JOBCITY) - any suggestions would be welcome
  15. Lhotch curmudgeon

    Users can search by the extra fields you create, they just have to chose a cetegory to search in first and the extra fields for that category to display.

    The reason for this is because the extra fields are not stored in the same database table as the ad. The reason for that is so that each ad category can have its own unique extra fields.
  16. CHRD Member

    I cant get this to work
    Im running v4.0.9 Developer

    I want to use the extra fields in showlistings and viewlistings

    also I cant get debug to work? I set allow in FF but it never been seen
  17. Lhotch curmudgeon

    Can you be a bit more specific when you say "I cant get this to work"?

    There are a couple methods in this thread that are being discussed so without knowing exactly what you are talking about its hard for anyone to offer help.

    As for the debug not working ive had the same issue on sites that are using the SEO mod, is that something you have installed?
  18. CHRD Member

    Yes Iv got the SEO mod installed.

    Iv followed this instructions but it still not working

    Is it built in 4.1 and will my 4.09 temps work in 4.1
  19. Lhotch curmudgeon

    Im not aware of any work around for having the SEO mod installed and the debug console. Ive always just disabled the SEO mod while I was using the console.

    I beleive there are some template changes between 4.0.9 and 4.1 so I think you will need to go through and make modifications to your existing templates to work with 4.1.

    As for getting extra fields, the first post tells you to add a php function called "getExtraField". However, in v4.0.9 that function already exists so if you followed the above instructions and added a duplicate function you are just causing problems and dont need to add that function to Listings.php.

    The other line of code thats supposed to be added needs to go into the function that gets the listings. That function is called "getAllListings" and if you look at it you should see a while loop after the query to get the ad contents. Adding the the following line adds a new element to the array and calls the function "getExtraField" and passes it an ad ID and a field ID of 4 and that function collects the extra field data and adds it to the array that hold the rest of the array data.

    $row['extrafield'] = $this->getExtraField($row['id'], 4);

    It can then be displayed via the template by using {$entry.extrafield}
  20. CHRD Member

    Yes I can see function getExtraField($id,$fieldid) in my
    includes/classes/kernel/Listings.php around line 486

    Then I added
    HTML:
    $row['extrafield'] = $this->getExtraField($row['id'], 4);  
    after

    HTML:
    $row['status']=$row['display'];  
    Is the SEO mod stopping this from working or just the DEBUG

    could you send a copy of listings.php?

Share This Page