RedJumpsuit

jobberBase custom development and support

 

Code School

Previous Job, Next Job links

this is for jobberBase 1.9.1

in this tutorial, i will show how you can add a Previous Job and Next Job links on your job posts, for easy navigation through your job site.

here are screenshots:

first job post
first

in between jobs
active

last job post
last

Steps:

1) open /_includes/class.Job.php and add this block on the Job class

// get next job
public function GetNextJob($category_id=false)
{
	global $db;
	$condition = '';
	$sanitizer = new Sanitizer;
 
	if ($category_id) {
		$condition .= ' AND category_id = '. $this->mCategoryId;
	}
 
	$sql = 'SELECT id AS next_id, title AS title, company AS company FROM '.DB_PREFIX.'jobs WHERE 1 '. $condition .' AND is_active = 1 AND id > '. $this->mId .' ORDER BY id ASC LIMIT 1';
	$result = $db->query($sql);
	$row = $result->fetch_assoc();
	if (!empty($row['next_id'])) {
		return $row['next_id'] .'/'. $sanitizer->sanitize_title_with_dashes($row['title'] . ' at ' . $row['company']) .'/';
	} 
}
 
// get previous job
public function GetPrevJob($category_id=false)
{
	global $db;
	$condition = '';
	$sanitizer = new Sanitizer;
 
	if ($category_id) {
		$condition .= ' AND category_id = '. $this->mCategoryId;
	}
 
	$sql = 'SELECT id AS prev_id, title AS title, company AS company FROM '.DB_PREFIX.'jobs WHERE 1 '. $condition .' AND is_active = 1 AND id < '. $this->mId .' ORDER BY id DESC LIMIT 1';
	$result = $db->query($sql);
	$row = $result->fetch_assoc();
	if (!empty($row['prev_id'])) {
		return $row['prev_id'] .'/'. $sanitizer->sanitize_title_with_dashes($row['title'] . ' at ' . $row['company']) .'/';
	}
}

2) open /_templates/default/_translations/translations_en.ini and add this on the [jobs] section

prev = "<< Previous Job"
next = "Next Job >>"
divider = "or"

3) open page_job.php and after this block:

// ######### list other jobs by the same company #########
$compjobs = $job->ApiGetJobsByCompany($info['company'], 5, false);
$sanitizedcomp = $sanitizer->sanitize_title_with_dashes($info['company']);
$smarty->assign('compjobs', $compjobs);
$smarty->assign('jobsat', $sanitizedcomp);
// ######### list other jobs by the same company #########

add this block:

// get next and previous jobs
$prev = $job->GetPrevJob(true); // set to true if previous job of the same category or leave blank
$next = $job->GetNextJob(true); // set to true if next job of the same category or leave blank
 
if (!empty($prev)) {
	$smarty->assign('prev', BASE_URL . URL_JOB . '/' . $prev);
}
if (!empty($next)) {
	$smarty->assign('next', BASE_URL . URL_JOB . '/' . $next);
}

4) finally, open /_templates/default/job.tpl and add the code below wherever you want the << Previous Job or Next Job >> links to appear.

{if $prev}<a href="{$prev}">{$translations.jobs.prev}</a>{else}{$translations.jobs.prev}{/if} {$translations.jobs.divider} {if $next}<a href="{$next}">{$translations.jobs.next}</a>{else}{$translations.jobs.next}{/if}

that should be all.

please consider donating if you like this tutorial or used it on your website 😉

Tagged as: , , , ,

3 Comments

Code School

  1. Hey,

    I tried this hack, but it didn’t show any Prev and Next on my site. I followed your instructions closely, and can not see what I have done wrong, if any. The last insert I put right after

    in /_templates/default/job.tpl, which I believe is the same you have in your sample.

    My site is http://www.ppJobb.com, if u care to take a look.

    btw, it might be something wrong on my site. For some reason, the “Apply Now” doesn’t appear on my job listings when it’s ticked off when posting. I checked the db, and it is registered. Don’t know if that can have anything to do with it?

    Ray

  2. Hey,

    I tried this hack, but it didn’t show any Prev and Next on my site. I followed your instructions closely, and can not see what I have done wrong, if any. The last insert I put right after

    //

    in /_templates/default/job.tpl, which I believe is the same you have in your sample.

    My site is http://www.ppJobb.com, if u care to take a look.

    btw, it might be something wrong on my site. For some reason, the “Apply Now” doesn’t appear on my job listings when it’s ticked off when posting. I checked the db, and it is registered. Don’t know if that can have anything to do with it?

    Ray

  3. Hey,

    I tried this hack, but it didn’t show any Prev and Next on my site. I followed your instructions closely, and can not see what I have done wrong, if any. The last insert I put right after

    ………………..– #job-listings —

    in /_templates/default/job.tpl, which I believe is the same you have in your sample.

    My site is http://www.ppJobb.com, if u care to take a look.

    btw, it might be something wrong on my site. For some reason, the “Apply Now” doesn’t appear on my job listings when it’s ticked off when posting. I checked the db, and it is registered. Don’t know if that can have anything to do with it?

    Ray

Leave a Response