/ Published in: PHP
                    
                                        
getCategory returns the category ID, getSection returns the section alias. Great for CSS overrides
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
function getCategory() {
/** function for determining the category ID of a given page, referenced from:
* http://forum.joomla.org/viewtopic.php?f=466&t=302292
*/
$iId = JRequest::getVar('id',0);
$database = &JFactory::getDBO();
if(JRequest::getVar( 'view', 0) == "section"){
return JRequest::getVar( 'id', 0);
}else if(Jrequest::getVar( 'view', 0) == "category"){
$sql = "SELECT id FROM #__categories WHERE id = '$iId'";
$database->setQuery( $sql );
$row=$database->loadResult();
return $row;
}else if(Jrequest::getVar('view', 0) == "article"){
$sql = "SELECT catid FROM #__content WHERE id = ".$temp[0];
$database->setQuery( $sql );
$row=$database->loadResult();
return $row;
}
}
function getSection() {
/**
function for determining the section alias of a given page
*/
$menu = &JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()){
return 'home';
}
$iId = JRequest::getVar('id',0);
$database = &JFactory::getDBO();
if(JRequest::getVar( 'view', 0) == "section"){
$sql = "SELECT alias "
. "FROM #__sections WHERE id = ".$iId
;
$database->setQuery( $sql );
$row=$database->loadResult();
return $row;
}else if(Jrequest::getVar( 'view', 0) == "category"){
$sql = "SELECT a.alias "
. "FROM #__sections as a, #__categories as b "
. "WHERE (b.id = ".$iId ." "
. "AND a.id = b.section)"
;
$database->setQuery( $sql );
$row=$database->loadResult();
return $row;
}else if(Jrequest::getVar('view', 0) == "article"){
//$sql = "SELECT sectionid FROM #__sections as a, #__content as b WHERE b.sectionid = a.id AND b.id = ".$temp[0];
$sql = "SELECT a.alias"
. " FROM #__sections as a, #__content as b "
. " WHERE (b.id = ".$temp[0] . " "
. " AND a.id = b.sectionid)"
;
$database->setQuery( $sql );
$row=$database->loadResult();
if (!$row)
{
return 'general'; // account for 'uncategorized' articles
}
return $row;
}
URL: http://forum.joomla.org/viewtopic.php?f=466&t=302292
Comments
 Subscribe to comments
                    Subscribe to comments
                
                