Posted By

chrisaiv on 04/04/09


Tagged

php joomla


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

benrudolph
jhafner
jessibird
taimurian
mumra


Handy Conditional Statements for Joomla


 / Published in: PHP
 

URL: http://forum.joomla.org/viewtopic.php?f=469&t=336451

  1. //Write conditional code for a homepage
  2. <?php if (JRequest::getVar('view')=='frontpage') { ?>
  3. put the HTML for the banner here
  4. <?php } ?>
  5.  
  6.  
  7. //Write conditional code for a Section Page
  8. <?php if (JRequest::getVar('view')=='section') { ?>
  9. put the HTML for the banner here
  10. <?php } ?>
  11.  
  12. //Target a Section page with a particlar #id
  13. <?php if (JRequest::getVar('view')=='section' && JRequest::getVar('id')==1) { ?>
  14. put the HTML for the banner here
  15. <?php } ?>
  16.  
  17. //If on section 1, display this data, if on section 2, display this data
  18. <?php
  19. $db = &JFactory::getDBO();
  20. $id = JRequest::getVar('id');
  21.  
  22. if ( $id ) {
  23. if ( JRequest::getVar('view') == 'section' ) {
  24. $sectionid = $id;
  25. } elseif ( JRequest::getVar('view') == 'category' ) {
  26. $query = 'SELECT section FROM #__categories WHERE id = ' . (int) $id;
  27. $db->setQuery($query, 0, 1);
  28. $sectionid = $db->loadResult();
  29. } elseif ( JRequest::getVar('view') == 'article' ) {
  30. $query = 'SELECT sectionid FROM #__content WHERE id = ' . (int) $id;
  31. $db->setQuery($query, 0, 1);
  32. $sectionid = $db->loadResult();
  33. }
  34. } else {
  35. $sectionid = '';
  36. }
  37.  
  38. if ($sectionid != '' && $sectionid == 2) { ?>
  39. Code for Section #2 goes here
  40. <?php } elseif ($sectionid != '' && $sectionid == 3) { ?>
  41. Code for Section #3 goes here
  42. <?php }
  43. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jessibird on November 4, 2009

Thanks so much, this is ultra-handy!

Posted By: netfuel on March 29, 2011

Very cool. Thanks so much! www.netfuel.ca

You need to login to post a comment.