Yo have the ID of the category, so you can perform a database query to get the title
, like so:
Get the title from the ID:
// Get the category parameter value
// Define a default value of 0
$cat_id = $params->get('catOne', 0);
// Get instance of database connection
$db = JFactory::getDbo();
// Query the #__categories table in the database
$query = $db->getQuery(true);
$query->select($db->quoteName('title'))
->from($db->quoteName('#__categories'))
->where($db->quoteName('id') . ' = '. (int)$cat_id);
$db->setQuery($query);
// Try and get the result
try
{
$result = $db->loadResult();
}
catch (Exception $e)
{
// If there is no result, make the variable empty
$result = '';
}
// Display the result
echo $result;
Display a Link:
To display the URL for the category, you will need to import com_content's router:
require_once JPATH_SITE . '/components/com_content/helpers/route.php';
$link = JRoute::_('index.php?option=com_content&view=category&layout=blog&id=' . $cat_id);
echo '<a href="' . $link . '">' . $result . '</a>';
For multiple params, use a function:
function displayCategoryLink($id)
{
require_once JPATH_SITE . '/components/com_content/helpers/route.php';
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('title'))
->from($db->quoteName('#__categories'))
->where($db->quoteName('id') . ' = '. (int)$id);
$db->setQuery($query);
try
{
$result = $db->loadResult();
}
catch (Exception $e)
{
$result = '';
}
$link = JRoute::_('index.php?option=com_content&view=category&layout=blog&id=' . $id);
$html = '<a href="' . $link . '">' . $result . '</a>';
return $html;
}
displayCategoryLink($params->get('catOne', 0));
displayCategoryLink($params->get('catTwo', 0));
displayCategoryLink($params->get('catThree', 0));
displayCategoryLink($params->get('catFour', 0));
The function above is just basic. I would of course suggest you put the function in a class, in a helper.php file and call it properly
Hope this helps