grubix

Topic: Sidebar - show categories AND jobs

If you want to have this behaviour:
http://i53.tinypic.com/255oz94.png

First you need to run the following MySQL code, replacing PREFIXHERE with your own:

Code:
UPDATE `PREFIXHERE_jobberbase`.`settings` SET `description` = 'cities or categories or both can be shown in the sidebar',
`input_options` = 'categories|cities|both' WHERE `settings`.`id` =14;

Alternatively do this more easily through phpMyAdmin - just browse to the settings table, find the sidebar_show_what record (should be id 14) and then change the input_options to categories|cities|both. Changing the description field is obviously optional.

Now when you go the main settings admin page, you can choose the additional option "both" for the sidebar.

Go to your page_home.php file. Change the following if-else loop:

Code:
if (SIDEBAR_SHOW_WHAT == 'categories')
    {
        ...1
    }
    else
    {
        ...2
    }

to:

Code:
if (SIDEBAR_SHOW_WHAT == 'categories')
    {
        ...1
    }
    else if (SIDEBAR_SHOW_WHAT == 'cities')
    {
        ...2
    }
    else if (SIDEBAR_SHOW_WHAT == 'both')
    {
        ...3
    }

...1 is your old code for showing categories
...2 is your old code for showing cities
It goes without saying don't actually replace the code with "...1" and "...2" !! smile

...3 is a new if statement for showing the new 'both' setting.
Where ...3 is in the above code, you just need to put in the contents of ...1 AND the contents of ...2, i.e. the code for getting both your categories and your cities.
I also suggest you follow my other tutorial which shows you how to replace the categories code with code that only shows categories with 1 or more job in, since space will be at a premium showing both:
http://www.jobberbase.com/forum/post12148.html

Now go to your template's sidebar.tpl file.
Again we have to reconstruct the if-else loop. It's a nice easy universal copy-and-paste though, to get the styling shown in the image at the start of this post.

Replace:

Code:
                {if $smarty.const.SIDEBAR_SHOW_WHAT == 'categories'}
                    {foreach item=job from=$jobs_count_all_categs}
                    <strong>{$job.categ_count}</strong> {$translations.homepage.sidebar_for} <a href="{$BASE_URL}{$URL_JOBS}/{$job.categ_varname}/">{$job.categ_name}</a><br />
                    {/foreach}
                {else}
                    {foreach item=job from=$jobs_count_per_city}
                    <strong>{$job.jobs_in_city}</strong> {$translations.jobscity.sidebar_jobs_in} <a href="{$BASE_URL}{$URL_JOBS_IN_CITY}/{$job.city_ascii_name}/">{$job.city_name}</a><br />
                    {/foreach}
                    {if !$hide_other_cities_in_sidebar}
                    <strong>{$jobs_count_in_other_cities}</strong> {$translations.jobscity.sidebar_jobs_in} <a href="{$BASE_URL}jobs-in-other-cities/">{$translations.sidebar.other_cities}</a>
                    {/if}
                {/if}

with:

Code:
                {if $smarty.const.SIDEBAR_SHOW_WHAT == 'categories'}
                    {foreach item=job from=$jobs_count_all_categs}
                    <strong>{$job.categ_count}</strong> {$translations.homepage.sidebar_for} <a href="{$BASE_URL}{$URL_JOBS}/{$job.categ_varname}/">{$job.categ_name}</a><br />
                    {/foreach}
                {/if}    
                
                {if $smarty.const.SIDEBAR_SHOW_WHAT == 'cities'}
                    {foreach item=job from=$jobs_count_per_city}
                    <strong>{$job.jobs_in_city}</strong> {$translations.jobscity.sidebar_jobs_in} <a href="{$BASE_URL}{$URL_JOBS_IN_CITY}/{$job.city_ascii_name}/">{$job.city_name}</a><br />
                    {/foreach}
                    {if !$hide_other_cities_in_sidebar}
                    <strong>{$jobs_count_in_other_cities}</strong> {$translations.jobscity.sidebar_jobs_in} <a href="{$BASE_URL}jobs-in-other-cities/">{$translations.sidebar.other_cities}</a>
                    {/if}
                {/if}
                
                {if $smarty.const.SIDEBAR_SHOW_WHAT == 'both'}
                    <br/><strong>by category:</strong><br/>
                    {foreach item=job from=$jobs_count_all_categs}
                    <strong>{$job.categ_count}</strong> {$translations.homepage.sidebar_for} <a href="{$BASE_URL}{$URL_JOBS}/{$job.categ_varname}/">{$job.categ_name}</a><br />
                    {/foreach}
                    <br/><strong>by location:</strong><br/>
                    {foreach item=job from=$jobs_count_per_city}
                    <strong>{$job.jobs_in_city}</strong> {$translations.jobscity.sidebar_jobs_in} <a href="{$BASE_URL}{$URL_JOBS_IN_CITY}/{$job.city_ascii_name}/">{$job.city_name}</a><br />
                    {/foreach}
                    {if !$hide_other_cities_in_sidebar}
                    <strong>{$jobs_count_in_other_cities}</strong> {$translations.jobscity.sidebar_jobs_in} <a href="{$BASE_URL}jobs-in-other-cities/">{$translations.sidebar.other_cities}</a>
                    {/if}
                {/if}

Enjoy! You now have both categories AND cities counts showing in the sidebar on the homepage.
To do this on other pages, see other people's tutorials already on this forum.