0

I have a custom component where I have a category field in a view (backend). That gives me the category id in the front-end.

Now I want to know how I could fetch the category name from this catid. I tried JCategories class but was unsuccessful. When I Googled this question I only get DB Query examples as answers but there must be a better way to get the category name then to do a db query?

2
  • 1
    Please do your best to use correct English and grammar so that volunteers don't need to tidy up your question. At the very least, always make the word "i" uppercase. Also, please never use a sign off, esignature, or closing "thanks in advance" / "any suggestions welcome" / " can anyone help me?" -- these trailing bits of text add no value to the question and editors will rightly trim them away. If you wish us to know that you are "Tom" please edit your username and/or profile instead of using a sign off in your question body. – mickmackusa Sep 29 '20 at 13:06
  • Edited my question thanks for the feedback :) – TLWebdesignNL Sep 29 '20 at 13:55
2

Have you tried JTable?

$category = JTable::getInstance('category');
$category->load($catid);
echo $category->title; 

I'm not 100% sure that the above is totally correct. It might be 'categories' rather than 'category'.

1
  • Thanks Kiran that worked like a charm. I had already found another way, but that involved getting all categories and looping through them. This way is much cleaner. – TLWebdesignNL Sep 29 '20 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.