Return to Snippet

Revision: 44933
at April 21, 2011 00:35 by beneberle


Initial Code
function getSection($iId) {
/** function for determining the section ID of a given page, referenced from:
* http://forum.joomla.org/viewtopic.php?f=466&t=302292
*/

  $database = &JFactory::getDBO();
  if(JRequest::getVar( 'view', 0) == "section"){
    return JRequest::getVar( 'id', 0);
  }else if(Jrequest::getVar( 'view', 0) == "category"){
    $sql = "SELECT section FROM #__categories WHERE id = '$iId'";
    $database->setQuery( $sql );
    $row=$database->loadResult();
    return $row;
  }else if(Jrequest::getVar('view', 0) == "article"){
    $temp=explode(":",JRequest::getVar('id',0));
    $sql = "SELECT sectionid FROM #__content WHERE id = ".$temp[0];
    $database->setQuery( $sql );
    $row=$database->loadResult();
    return $row;
  }
}
$section_id=getSection(JRequest::getVar('id',0));

if (JRequest::getVar('option') == 'com_glossary') {
    $section_id = '10';
}

Initial URL
http://forum.joomla.org/viewtopic.php?f=466&t=302292

Initial Description
function for determining the section ID of a given page. Good to include in a templatetools.php file inside of a template to set up some custom conditional logic

Initial Title
Joomla 1.5 - Get Section Function - Template Tools

Initial Tags
joomla

Initial Language
PHP