Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get category by ID of child article - Joomla 2.5 API

I have an ID of an article, and want to know it's parent category details. To get category details by it's ID i've read an API that i need code like this:

 $categories = JModelLegacy::getInstance('Categories', 'ContentModel', array('ignore_request' => true));
 $categories->setState('filter.published', 1);
 $categories->setState('filter.access', $access);
 $items = $categories->getItems();

But this gives me (via j-dump) a list of objects not filtered at all. What setState filter i must apply to: 1) only one result 2) filtered by category ID (visible in admin, not asset ID)= XX

And, if possible - how to get article's parent category?

like image 729
shershen Avatar asked Dec 05 '25 17:12

shershen


1 Answers

I get a specific category like this:

$options    = array();
$categories = JCategories::getInstance('Content', $options);
$category   = $categories->get($article->catid);

From there you can use

$parent     = $category->getParent();

To get the parent category of the selected $category.

Update: To get the catid of the article, use this MySQL query:

SELECT `catid` FROM `#__content` WHERE `id` = $article_id
like image 54
Bakual Avatar answered Dec 08 '25 09:12

Bakual



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!