PHP Code

How to detect the home page on a Joomla site

Create beautiful Joomla websites with a flexible layout from iJoomla.com

Recently I had to add some PHP code to the template of a Joomla site I run, but I wanted that code to run on the homepage only. Considering the fact that I'm using an SEF component on the site, it was tricky, but here's the line of PHP code I was able to do it with:


$pge = $_SERVER['QUERY_STRING']; if ($pge == "/index.php"||$pge == "") {
     //do stuff
}

Create beautiful Joomla websites with a flexible layout from iJoomla.com

Share

8 Comments

  1. Top man, that's a simple enough line… all I gotta do now is think of stuff to do now that I know it's do-able.

  2. Joomla Developer

    Had to Modify your code to work for me as below

    Your Page Title ";
    }
    ?>

  3. Joomla Developer

    Your Page Title ";
    } ?>

  4. Joomla Developer


    Your Page Title ";
    }
    ?>

  5. Joomla Developer

    $pge = $_SERVER['QUERY_STRING']; if ($pge == "/index.php"||$pge == ""||$pge == "option=com_frontpage&Itemid=1") {
    //do stuff
    echo " Your Page Title ";
    }

  6. thank you very very much! that literally solved my provlem with adding a special flash script just to the startpage.

    you are genius! thanks again!

  7. why not

    if ( JURI::base() == JURI::current() )
    {
    //do stuff
    }

  8. That is great. but it doesnt seem to work with URL rewrites

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image