Get article category by article ID

I have article ID. And I don't know how to get the category name and other params this article. There are no category name in xxxx_content some article.

Please help!

Upvotes: 0

Views: 607

Answers (1)

ilias
ilias

Reputation: 1345

Wherever you are you'll have to query the database to fetch all the article information that you need. For instance, in your case, since the articles in the #__content table have the category id stored you'll have to join the category table as it's already been done in the com_content component.

Check the file components/com_content/models/articles.php and in line 222 you'll see this:

// Join over the categories.
        $query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias')
            ->join('LEFT', '#__categories AS c ON c.id = a.catid');

This is where the category name is taken from the #__categories table. In a similar way you'll be able to get other article info too.

Upvotes: 1

Related Questions