Return to Snippet

Revision: 13007
at April 4, 2009 11:28 by chrisaiv


Initial Code
//Write conditional code for a homepage
<?php if (JRequest::getVar('view')=='frontpage') { ?>
   put the HTML for the banner here
<?php } ?>


//Write conditional code for a Section Page
<?php if (JRequest::getVar('view')=='section') { ?>
   put the HTML for the banner here
<?php } ?>

//Target a Section page with a particlar #id
<?php if (JRequest::getVar('view')=='section' && JRequest::getVar('id')==1) { ?>
   put the HTML for the banner here
<?php } ?>

//If on section 1, display this data, if on section 2, display this data
<?php
   $db = &JFactory::getDBO();
   $id = JRequest::getVar('id');
   
   if ( $id ) {
      if ( JRequest::getVar('view') == 'section' ) {
         $sectionid = $id;
      } elseif ( JRequest::getVar('view') == 'category' ) {
         $query = 'SELECT section FROM #__categories WHERE id = ' . (int) $id;
         $db->setQuery($query, 0, 1);
         $sectionid = $db->loadResult();
      } elseif ( JRequest::getVar('view') == 'article' ) {
         $query = 'SELECT sectionid FROM #__content WHERE id = ' . (int) $id;
         $db->setQuery($query, 0, 1);
         $sectionid = $db->loadResult();
      }
   } else {
      $sectionid = '';
   }
   
   if ($sectionid != '' && $sectionid == 2) { ?>
      Code for Section #2 goes here
   <?php } elseif ($sectionid != '' && $sectionid == 3) { ?>
      Code for Section #3 goes here
   <?php }
?>

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

Initial Description

                                

Initial Title
Handy Conditional Statements for Joomla

Initial Tags
php, joomla

Initial Language
PHP