Hi all, Would it be possible to create a copy of the plugin {total_listing} to only show the number of listings for a certain catergory either via category name or category id ?, as the code is short i have copied it here, but as usual im not sure what to put where so any help gratefully received Jason * @param return int Total number. */ function smarty_function_total_listings($params, &$smarty) { global $db; $sSQL="SELECT COUNT(*) AS total FROM ".PREFIX."listings WHERE expiration > NOW() AND display = 'Y'"; $result=$db->query($sSQL); $rs=$result->fetch(); $total_listings=$rs['total']; return $total_listings; }
You can try something like this: PHP: function smarty_function_total_listings($params, &$smarty){ global $db; $category = ''; foreach ($params as $_key=>$_value) { switch ($_key) { case 'category': $$_key = (int)$_value; break; } } $sSQL="SELECT COUNT(*) AS total FROM ".PREFIX."listings WHERE expiration > NOW() AND display = 'Y'"; if ($category != '') { $sSQL .= ' AND section = '. $category; } $result=$db->query($sSQL); $rs=$result->fetch(); $total_listings=$rs['total']; return $total_listings;} Then in your template: Code: {total_listings category=1}
HI Eric, I tried as you suggested but it isnt working, it just blanks out the whole page, any other thoughts ? By the way thanks for the help Jason
Make sure in the plugin file you but that function inside <?php ?> tags. That wasn't included in the sample.