Trying to get category id on blog page

1.8k Views Asked by At

I'm trying to get category id of each post with this:

$catid = JRequest::getInt('catid'); 

I put this script on blog_item.php

But I get only 0 to all posts

1

There are 1 best solutions below

2
On BEST ANSWER

The template is loaded with the context of a ContentViewCategory. It allows only one main category, and its id can be obtained by using:

$mainCatid = $this->category->id

The current item's immediate parent's id can be obtained by querying the item's catid property. There are plenty of other properties available, including category name.

$catid = $this->item->catid