I need to get current article category id, in older joomla version I used:
<?php $catid = JRequest::getInt('catid'); echo $catid; ?>
But in Joomla 3.2 I get 0.
I need to get current article category id, in older joomla version I used:
<?php $catid = JRequest::getInt('catid'); echo $catid; ?>
But in Joomla 3.2 I get 0.
You can eliminate the extra database query by taking advantage of the fact that the article model instance is cached and so is the query result for the current article. So, use the content model class to get what you are after.
$app = Jfactory::getApplication();
$input=$app->input;
if ($input->getCmd('option')=='com_content'
&& $input->getCmd('view')=='article' ){
$cmodel = JModelLegacy::getInstance('Article', 'ContentModel');
$catid = $cmodel->getItem($app->input->get('id'))->catid;
}
NB if you are calling this from a system plugin before the application is rendered you will have to also have to use require_once to include the content model. The above code will work fine in in most situations such as a template or content plugin.
Try this
<?php echo $this->item->catid;?>
This work in blog_item.php the category folder, and blog.php of article folder.
I know this is an old post but, it helped me figure out just what I needed.
To get the catid, view, and layout:
$a = JFactory::getApplication();
$input=$a->input;
$catId = $input->getCmd('id');
$view = $input->getCmd('view');
$layout = $input->getCmd('layout');
It will depend on your context. In joomla 3 the category id is not in the www-query when you display an article. So you need to get it from the article item. To investigate if catid is available in some of your variables, you could try to do:
<?php print_r($this); ?>
or
<?php print_r(get_defined_vars()); ?>
To get the catid directly in the template, if it's not available in the output above, you might do something like this:
$input=Jfactory::getApplication()->input;
if($input->getCmd('option')=='com_content'
&& $input->getCmd('view')=='article' ){
$db=JFactory::getDbo();
$db->setQuery('select catid from #__content where id='.$input->getInt('id'));
$catid=$db->loadResult();
}
(this will generate some extra database-traffic) regards Jonas
You have to look carefully at the url.
Instead of:
<?php
$catid = JRequest::getInt('catid');
echo $catid;
?>
it could be:
<?php
$catid = JRequest::getInt('id');
echo $catid;
?>
Below is an example URL I have:
index.php?option=com_content&view=category&layout=blog&id=8&Itemid=103
You see the category id can be found in id=8