How to get database information from Joomla category

99 views Asked by At

I know how I can retrieve all information from a article in the database. I am trying to do the same thing for a category. And just for clarification, I am talking about when view is equal to category (index.php?option=com_content&view=category). Below is how I can retrieve any information for a article, when I am on a article page, I want to do the same exact thing, but when I am on a category page. Thanks!

$input = JFactory::getApplication()->input;
$articleId = $input->getInt('id');
$article = JTable::getInstance('content');
$article->load($articleId);
$articleTitle = $article->get('title');
2

There are 2 answers

5
Lodder On

You can check if the view is currently on category by using the following:

$input  = JFactory::getApplication()->input;
$option = $input->get('option', '');
$view   = $input->get('view', '');

if ($option == 'com_content' && $view == 'category')
{
    // Do something
}

You will see that I'm also checking for the option (component in use) as other components use a category view.

2
antfuentes87 On

All I had to do was change content to category and I was able to access all data within the category table using the same method I did with the content.

$input = JFactory::getApplication()->input;
$catId = $input->getInt('id');
$cat = JTable::getInstance('category');
$cat->load($catId);