25Jun/097
Cities Tag-Cloud
Cities can be filtered much the same way as Companies ("/jobs-at" and "jobs-in"), since JobberBase 1.7. The overview of Companies in a tagcloud-like way, that has been around since early versions, hasn't been added to the Cities yet though.
Modification Features:
- Introduces a function that returns all cities that have at least one job
- Adds an overviewpage (similar to /companies), where cities with more jobs get bigger
- Can be used for an overview of cities with jobs available on the frontpage
Example Page: TelefonischWerk.nl Cities Overview
1. Open "index.php":
Find:
// per category case 'jobs': require_once 'page_category.php'; $flag = 1; break;
Add above:
// cities case 'cities': require_once 'page_cities.php'; $flag = 1; break;
2. Create a new file "page_cities.php":
<?php $city_array = get_cities_cloud(); $smarty->assign('cities_overview', $city_array); $smarty->assign('cities_count', count($city_array)); $html_title = $translations['jobscity']['page_title']; $template = 'cities.tpl'; ?>
3. Create a new file "_templates/cities.tpl":
{include file="header.tpl"} <div id="content"> <!-- #job-listings --> <h3 class="page-heading">{$translations.jobscity.title}</h3> {section name=tmp loop=$cities_overview} <span class="company-tag-{$cities_overview[tmp].tag_height}"> <a href="{$BASE_URL}jobs-in/{$cities_overview[tmp].varname}">{$cities_overview[tmp].name} ({$cities_overview[tmp].count})</a> </span> {/section} {$translations.jobscity.total}: <strong>{$cities_count}</strong> {$translations.jobscity.cities}</div> <!-- /content --> {include file="footer.tpl"}
4. Open "_templates/footer.tpl":
Find:
<a href="{$BASE_URL}companies/" title="{$translations.footer.companies_title}">{$translations.footer.companies}</a><br />
Add below:
<a href="{$BASE_URL}cities/" title="{$translations.footer.cities_title}">{$translations.footer.cities}</a><br />
5. Open "_includes/translations.ini":
Find:
[footer]
Add below:
cities_title = "Cities" cities = "Cities"
Find:
[jobscity]
Add below:
page_title = "Overview of cities" title = "Cities with jobs available" total = "Total" cities = "cities" jobs_at = "Jobs in"
6. Open "_includes/functions.php":
Find:
function add_single_quotes($arg) { /* single quote and escape single quotes and backslashes */ return "'" . addcslashes($arg, "'\\") . "'"; }
Add below:
function get_cities_cloud() { global $db; $city_array = array(); $sql = 'SELECT c.id, c.name, c.ascii_name, COUNT(*) AS nr FROM cities c INNER JOIN jobs j ON (j.city_id = c.id ) WHERE j.is_active = 1 GROUP BY c.name'; $cities = $db->QueryArray($sql); foreach ($cities as $city) { $nr = $city['nr']; if ($nr < 2) { $tag_height = 1; } else if ($nr >= 2 && $nr < 3) { $tag_height = 2; } else if ($nr >= 3 && $nr < 4) { $tag_height = 3; } else if ($nr >= 4 && $nr < 5) { $tag_height = 4; } else if ($nr >= 5 && $nr < 6) { $tag_height = 5; } else if ($nr >= 6) { $tag_height = 6; } $city_array[] = array('name' => $city['name'], 'varname' => $city['ascii_name'], 'count' => $nr, 'tag_height' => $tag_height); } return $city_array; }






June 28th, 2009 - 16:15
Great modification of the company cloud. I would suggest a small change in the code that’s added to functions.php. Instead of “SELECT c.id, c.name, c.ascii_name, COUNT(*) AS nr FROM cities c INNER JOIN jobs j ON (j.city_id = c.id ) GROUP BY c.name” I would use “SELECT c.id, c.name, c.ascii_name, COUNT(*) AS nr FROM cities c INNER JOIN jobs j ON (j.city_id = c.id ) GROUP BY c.name ORDER BY Rand()”. This way you shuffle the cities each time they’re displayed.
Keep it up!
July 3rd, 2009 - 15:01
I’ve just added tagging when job posting.
http://www.redjump.co.cc/2009/04/18/add-tags-when-posting-a-job/
Can your cities tag cloud be easily modified to a tag cloud using the post tags?
Thanks
July 8th, 2009 - 11:09
Some parts of it could be used, but it would still need about 50% new code I guess. I’ll have a look at it and release it as a new post once it’s done.
July 21st, 2009 - 11:24
Typo Error in Cities.tpl: Instead of {$translations.jobscity.cities_overview} it should be {$translations.jobscity.cities}
July 21st, 2009 - 18:22
One more error…it shows cities with jobs too which are currently inactive.
July 21st, 2009 - 18:34
Modify the query as SELECT c.id, c.name, c.ascii_name, COUNT(*) AS nr FROM cities c INNER JOIN jobs j ON (j.city_id = c.id ) WHERE j.is_active = 1 GROUP BY c.name
July 21st, 2009 - 18:55
Thanks! I’ll modify it in a bit, good find