Display Category name from CompanyDirectory in Summary view

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
Zoorlat

Display Category name from CompanyDirectory in Summary view

Post by Zoorlat »

I needed to create a filter-by-category functionality in a website's company directory/google maps page.
See here: http://www.sundborn.com/foretag

The problem was to get and display the Category name of the chosen categoy (and format the buttons accodingly). Unfortunately the category name is not passed in the smarty-variables (as far as I understand, I might have missed something here.)

The solution was to get the category-id and look-up the category name in the database with the help of some smarty and a simple UDT:

In the tempate I used this smarty:

Code: Select all

{assign var=catId value="/"|explode:$smarty.get.page}
to get the catId.

I can then use this simple UDT to get the category name:

Code: Select all

global $gCms;
$db = $gCms->GetDb();

$cat_id = $params['catid'];

$data = mysql_query("SELECT * FROM  cms_module_compdir_categories") 
 or die(mysql_error()); 

while($info = mysql_fetch_array( $data )) 
 { 
 	if($info['id'] ==  $cat_id)
		{
			$cat_name = $info['long_name'];
        }
 }

print_r($cat_name);
The UDT is called by:

Code: Select all

{getcategory catid=$catId.2}
A rather rough solution, admittedly. But it got the job done ;)
Post Reply

Return to “Tips and Tricks”