Joomla 1.5 - Get Section Function - Template Tools


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. function getSection($iId) {
  2. /** function for determining the section ID of a given page, referenced from:
  3. * http://forum.joomla.org/viewtopic.php?f=466&t=302292
  4. */
  5.  
  6. $database = &JFactory::getDBO();
  7. if(JRequest::getVar( 'view', 0) == "section"){
  8. return JRequest::getVar( 'id', 0);
  9. }else if(Jrequest::getVar( 'view', 0) == "category"){
  10. $sql = "SELECT section FROM #__categories WHERE id = '$iId'";
  11. $database->setQuery( $sql );
  12. $row=$database->loadResult();
  13. return $row;
  14. }else if(Jrequest::getVar('view', 0) == "article"){
  15. $temp=explode(":",JRequest::getVar('id',0));
  16. $sql = "SELECT sectionid FROM #__content WHERE id = ".$temp[0];
  17. $database->setQuery( $sql );
  18. $row=$database->loadResult();
  19. return $row;
  20. }
  21. }
  22. $section_id=getSection(JRequest::getVar('id',0));
  23.  
  24. if (JRequest::getVar('option') == 'com_glossary') {
  25. $section_id = '10';
  26. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.