CMS Made Simple Forums
https://forum.cmsmadesimple.org/

Display Category name from CompanyDirectory in Summary view
https://forum.cmsmadesimple.org/viewtopic.php?f=4&t=70397
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: 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:
\$1:
{assign var=catId value="/"|explode:$smarty.get.page}

to get the catId.

I can then use this simple UDT to get the category name:
\$1:
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:
\$1:
{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
http://www.phpbb.com/