Posted By

beneberle on 04/21/11


Tagged

joomla


Versions (?)

Joomla 1.5 - Get Section Function - Template Tools


 / Published in: PHP
 

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

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

  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. }

Report this snippet  

You need to login to post a comment.