RedJumpsuit

jobberBase custom development and support

Category Jobs Filter

the jobs listed in the category can get long and sometimes irrelevant anymore to those looking for jobs, so to keep the list relevant, there is a way job seekers can filter the jobs in the category they are looking at. here is a sample screenshot:

filter-jobs

and here is an instruction on how it can be done:

Open up /_includes/translations.ini and add this:

[header]
filter_jobs = "Filter Jobs"
 
[filter]
day = "24 Hours"
week = "1 Week"
month = "1 Month"

Open up /_templates/sidebar.tpl

Before the line:

{if $CURRENT_PAGE != ''}

Add this block:

{if $current_category != 'home' && $current_category != ''}
<h4>{$translations.header.filter_jobs}</h4>
<ul>
    <li>
		{if $filter != 'h'}
			<a href="{$BASE_URL}advanced/{$current_category}/h/">{$translations.filter.day}</a>
		{else}
			<strong><a href="#">{$translations.filter.day}</a></strong>
		{/if}
	</li>
    <li>
		{if $filter != 'w'}
			<a href="{$BASE_URL}advanced/{$current_category}/w/">{$translations.filter.week}</a>
		{else}
			<strong><a href="#">{$translations.filter.week}</a></strong>
		{/if}
	</li>
    <li>
		{if $filter != 'm'}
			<a href="{$BASE_URL}advanced/{$current_category}/m/">{$translations.filter.month}</a>
		{else}
			<strong><a href="#">{$translations.filter.month}</a></strong>
		{/if}
	</li>
</ul>
<br />
{/if}

Create a file on the root folder named ‘page_advancedsearch.php’ and paste this code:

<?php
 
$list = new AdvancedSearch();
$the_jobs = array();
 
$the_jobs = $list->filterjobs($extra,50,$id);
 
$smarty->assign('jobs', $the_jobs);
$smarty->assign('current_category', $id);
$smarty->assign('filter', $extra);
 
$smarty->assign('seo_title', get_seo_title($id));
$smarty->assign('seo_desc', get_seo_desc($id));
$smarty->assign('seo_keys', get_seo_keys($id));
 
$template = 'category.tpl';
?>

Create a file on your /_includes folder called ‘class.AdvancedSearch.php’ and paste this code:

<?php
/**
 * jobber job board platform
 *
 * @author    RedJumpsuit <myredjumpsuit@gmail.com>
 * @web        www.redjump.co.cc
 *
 * Advanced Search is used for more extensive searching
 */
 
class AdvancedSearch
{
    function __construct()
    { }
 
    public function filterjobs($filter,$per_page=50,$catname)
    {
        global $db;
        $jobs = array();
 
        $condition = '';
 
        // 1 day
        if ($filter == 'h')
        {
            $condition = ' AND a.created_on >= DATE_SUB(NOW(),INTERVAL 1 DAY) ';
        }
        // 1 week
        elseif ($filter == 'w')
        {
            $condition = ' AND a.created_on >= DATE_SUB(NOW(), INTERVAL 1 WEEK ) ';
        }
        // 1 month
        else
        {
            $condition = ' AND a.created_on >= DATE_SUB(NOW(),INTERVAL 1 MONTH ) ';
        }
 
         $sql = 'SELECT a.*, b.name AS city_name, c.name AS category_name, REPLACE(LOWER(a.title)," ","-") AS url_title
                    FROM jobs a, cities b, categories c
                    WHERE a.city_id = b.id
                        AND a.category_id = c.id
                        AND c.var_name = "'. $catname .'"'. $condition . ' LIMIT 0, '. $per_page;
 
        $result = $db->query($sql);
        while ($row = $result->fetch_assoc())
        {
            $jobs[] = $row;
        }
 
        if ($jobs)
        {
            return $jobs;
        }
 
    }
}
?>

Second to the last, open your index.php and under this block:

// per category
case 'jobs':
    require_once 'page_category.php';
    $flag = 1;
    break;

Add this block

// per filter
case 'advanced':
    require_once 'page_advancedsearch.php';
    $flag = 1;
    break;

Finally, open up your config.php file and add this at the end of the require_once class list:

// advanced search
require_once '_includes/class.AdvancedSearch.php';

15 Comments

  1. I am missing city names on filtered results.

  2. You are a life saving rockstar!!!!

  3. hi, i noticed this ;) just need to rename the city name to the name displayed by the template. will update this tutorial later! thanks for the bug report!

  4. Thanx, replaced city_name with location in class.AdvancedSearch.php and it works!

  5. I tried to apply the mod, but it returns a blank page. Please help.

    the filter links have the format of “http://www.sitename.com/advanced/catgegory/h/”

    thanks.

  6. hi, please double-check your code with the instructions ;) a lot of people have implemented this mod and you are the first to report an error for this!

  7. Not work change city_name for city_location … anyone have a response?

  8. This php code is great. very easy to install.

  9. pls update code for 1.8

    thx

  10. How to get date formatted as 0ct 17th?

  11. Hi,

    This looks really great. Is this for v1.7 at the moment?

    Would it be possible to get for v1.8 please.

    Thanks again

  12. can i do change change the main tabs of the website instead of job with cities and can i use that feature once i do that thanks in advance

  13. more explainations i want to add a dropdown tab containing find a job contains these choises find a job,cities

Leave a Response