Business, Tech, Life, and Whatever else

Import Listings into 68 Classifieds

by Eric Barnes on August 18, 2009

Recently I needed a way of importing listings from another site into a 68 Classifieds site. As of right now 68 Classifieds doesn’t have an api so the only real way of doing it is to create some custom code to interact with the script. In this post I will outline how I got it working so if you ever have the need you can do it too. Keep in mind this is very crude and just enough to get the job I needed done.

The Data

The data you are importing needs to be a delmited file. I used a pipe delimited text file with the following lines:

OWNER|TITLE|SECTION|LINK|DESCRIPTION|PRICE|MAKE|MODEL|HOURS|SERIAL|LOCATION|
1|Test Import|1|http://yoursite.com|Test desc|2399|Ford|Taurus|55000|none|My Town
1|Test Import 2|1|http://yoursite.com|Test desc 2|2399|Toyota|Tundra|55000|none|My Town

The first line is just the header which is not used but I included it for reference. The next two lines are two different vehicles to import. The important step is to make sure the lines align with the heading line and to have each on their own line.

The Import Script

The import script is where all the processing will be. This file is designed to be saved in your 68 Classifieds root. You can view and download the full file from GitHub. I will go through all the sections below so you can see how to modify it suit your needs.

At the top of this file is this section:

$expiration = '30'; // Change 30 to the number of days these should expire.
$make_extra_field_id = 6; // The id of the make extra field
$model_extra_field_id = 7; // The id of the model extra field
$hours_extra_field_id = 8; // The id of the hours extra field
$serial_extra_field_id = 9; // The id of the serial extra field
$location_extra_field_id = 10; // The id of the location extra field

This allows you define what extra fields you are using and have them line up with your data.txt file. As you can see I am setting the expiration for 30 days, then defining the id of each extra field I am using.

The next part you will probably want to modify is the for loop. Inside this loop I am assigning out the data. This looks like this:

$data['owner'] = $arr[0];
$data['title'] = $arr[1];
$data['section'] = $arr[2];
$data['url'] = $arr[3];
$data['description'] = $arr[4];
$data['price'] = $arr[5];

Basically the $arr[number] is a map to the data file. So $arr[0] is the data in the first pipe and on on. Just remember it always starts with zero instead of one.

The final piece of data is the extra fields which look like this:

$extra['make'] = $arr[6];
extra_field($listingid, $make_extra_field_id, $extra['make']);

The first line $extra['make'] = $arr[6]; is just like above this maps to 5th deliminator in the data file. Next we call the function extra_field which takes the listingid, the extra field id, and finally the text as parameters.

The Full File

Wrap Up

Trying to explain this was actually a lot harder than I thought. So if you need any clarification on anything please comment below.

You May Also Be Interested In...

Code Igniter Template Tutorial
July 7, 2008

Classifieds Twitter Feeder
March 14, 2009

Secure web forms with tokens
January 8, 2009

reCaptcha Module
February 11, 2009

Subscribe Now

If you enjoyed this post, you will definitely enjoy my others. Subscribe to the feed to get instantly updated for those awesome posts soon to come.


  • guillo
    I will do that. I already have a spare database for all my testings. With the following questions answered, I might be able to get on my way to testing.

    Can I create an anonymous listing owner?

    What category will the listings be place in? I dont see any reference to categories in the code

    Can I use fields already present in 68Class and not extra fields?

    Once I upload the php file above and the data.txt file, how do i run the script?
  • Hi,

    This is not a simple plug and play script. You are going to have to do some manual changes to make it suit your site. Also yes extra fields are created from admin -> categories.

    I would suggest installing a test copy of 68c on a separate database and then play with this. That way you will not risk messing up a current install and give you a better of the coding behind it.
  • guillo
    Eric, i really really really need your help with this. I finished the set up of the site and would like to add just a couple of hundred listings before marketing the page.

    I already have the listings. Basically, I just need to format the data and upload it to the server.

    I dont see categories in the PHP. where will the listings be placed then?

    When you talk about extra fields... what do you mean?
    (the extra fields created in the categories menu in admin?)

    Can The fields used originally by 68classifieds be used with this procedure? if so, where can I find the field ID#?

    For Example: The listings I want to import include the following.
    Contact name
    Telephone Number
    Listing Title
    Location
    Make and Model (in the vehicle category only, not in the housing, for example)
    Price

    Any and all help will be appreciated!
  • guillo
    This is an extremely important detail that most of us might want to implement.

    Im just not at all familiar with what to do with the information you provided. Im a really sorry if i make you explain it again, but I have a ton of listings i need to import.

    I have downloaded the file.

    When you talk about extra fields... what do you mean?
    (the extra fields created in the categories menu in admin?)


    Can The fields used originally by 68classifieds be used with this procedure? if so, where can I find the field ID#?

    For Example: The listings I want to import include the following.
    Contact name
    Telephone Number
    Listing Title
    Location
    Make and Model (in the vehicle category only, not in the housing, for example)
    Price

    I will not be including a listing owner as the source file does not provide it. can I assign a anonymous owner?

    What do I do with this?

    Quote:
    "
    The final piece of data is the extra fields which look like this:

    $extra['make'] = $arr[6];
    extra_field($listingid, $make_extra_field_id, $extra['make']);

    The first line $extra['make'] = $arr[6]; is just like above this maps to 5th deliminator in the data file. Next we call the function extra_field which takes the listingid, the extra field id, and finally the text as parameters. "

    Finally, how do i implement the actual script in order to import the data.txt showing the listings in the page?
  • Stuart
    Ok thanks for this, much appreciated.
  • Stuart
    Hi Eric

    This doesnt include all the extra fiels though, Thanks for your help, can this script not be modifed to exprt as well?
  • Sorry I didn't catch that. :( I will make a new post with instructions for exporting. It may be a day or two before I can get to it.
  • Stuart
    same format is fine. I can then just import into excel as a data file
  • Hi Stuart please have a look here:
    http://www.68classifieds.com/forums/v4-1-questi...
  • Stuart
    Hi Eric

    I want to use this import feature but I also need an export feature. What do I need to change in this to make it work?
  • Are you wanting to export in the same format as this feed imports? Or some other format?
blog comments powered by Disqus