Filter Listings by Country Using TemplateCodes Module – How to

As I said in the system review, the Listing Filter module can filter ads by State or using an extra (custom) field but can’t be setup to filter by countries. There’s a way to make it do that though but you need to mess with the gears of the system, opening & editing a number of PHP files.

Note: I'm not a programming guru, I used some code hints & went through trials & failures to make this work & it may not be the best way to do it. Please backup your files & even database before you proceed & be careful when altering the codes.

1st, if it’s enabled, you may want to deactivate the Listing Filter module from your 68Classifieds admin panel before you start editing & uploading files.

2. Now go & open the index.php located in , use Notepad++ or a similar text editor.

Find these lines:

if (empty($config['lfilter_field'])) {
$sSQL = "SELECT name FROM " . PREFIX . "states ORDER BY name";

Replace with this:

if (empty($config['lfilter_field'])) {
$sSQL = "SELECT countryName FROM " . PREFIX . "countries ORDER BY countryName";

We’ve just asked the script to look in the MySQL database, for the Countries table (prefix_countries) & the Countries name field (countryName) instead of States table & name field.

3. Look in the same file for this line:

$output .= '<li><a class="cls_listingfilter_choose" href="modules.php?mod=listingfilter&action=select&filter=' . htmlspecialchars(stripslashes($rs['name'])) . ' ">' . htmlspecialchars(stripslashes($rs['name'])) . '</a></li>';

Replace name with countryName to get this:

$output .= '<li><a class="cls_listingfilter_choose" href="modules.php?mod=listingfilter&action=select&filter=' . htmlspecialchars(stripslashes($rs['countryName'])) . ' ">' . htmlspecialchars(stripslashes($rs['countryName'])) . '</a></li>';

4. Now in the same folder, open the hooks.php file, find u.state & change it to , you should find it twice (lines 86 & 111 in my version), do the replacement twice.

5. Now go & open function.css_listings_horizontal.php , a file inside

Look for 'users AS u WHERE AND u.state='

Replace u.state with

6. Open the file function.tc_jcarousel.php inside

Do the same, look for 'users AS u WHERE AND u.state=' & replace u.state with

That's it! Now you can activate your module & see the result. But you should remember, if later you decide that you want to use the filter with an extra field instead of countries, before you do that get back the files to their original state!


Comment ( 1 )

Comments are closed.