CMS Made Simple Forums

Display Category name from CompanyDirectory in Summary view
Page 1 of 1

Author:  Zoorlat [ Tue Jun 10, 2014 2:48 pm ]
Post subject:  Display Category name from CompanyDirectory in Summary view

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

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:
{assign var=catId value="/"|explode:$}

to get the catId.

I can then use this simple UDT to get the category name:
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'];


The UDT is called by:
{getcategory catid=$catId.2}

A rather rough solution, admittedly. But it got the job done ;)

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group