1Jun/100
Find Joomla section ID for article or category
Sometimes when coding a Joomla template it may be handy to know the section ID of the article or category the user is viewing.
Here is some PHP code you could insert in your template to achieve this (for Joomla 1.5);
$db =& JFactory::getDBO();
if(JRequest::getVar(‘view’)==’article’){
$query = “SELECT sectionid FROM #__content WHERE id=’”.JRequest::getVar(‘id’).”‘”;
$db->setQuery($query);
$sectionid = $db->loadResult();
}
if(JRequest::getVar(‘view’)==’category’){
$query = “SELECT sectionid FROM #__content WHERE catid=’”.JRequest::getVar(‘id’).”‘”;
$db->setQuery($query);
$sectionid = $db->loadResult();
}
Using this, you could for example control which graphics or CSS file are loaded depending on the section of the article/category.
