PHP noob here: help on PHP function like in WP

Discussion in 'PHP' started by jehzlau, Dec 25, 2008.

  1. #1
    Hi, I'm a PHP noob and I need help with a simple PHP function.

    I need help how can I undisplay a certain text in PHP (when in homepage), just like this function in Wordpress

    <?php if (!is_home()) {  ?>
    The Text that hides when I am in homepage
    <?php} ?>
    PHP:
    How can I do the same if I'm only into plain PHP? no CMS... :(

    I hope PHP gurus here got my point :(
     
    jehzlau, Dec 25, 2008 IP
  2. mordimi

    mordimi Active Member

    Messages:
    177
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2




    here on the fly i can tell you to declare a variable $home where it will be filled with your text to be undisplayed
     
    mordimi, Dec 25, 2008 IP
  3. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #3
    <?php
    function is_home(){
    //Change index.php to the path to your homepage.
    if($_SERVER['REQUEST_URI'] == /index.php){
    $home = 1;
    } else {
    $home = 0;
    }
    return $home;
    }

    ?>

    That should work. To call upon it, you would have to use something like this:

    <?php
    $home = is_home();
    if ($home = 1){
    //You're on the home page. Display what you want below.
    }
    ?>

    Good?
     
    qualityfirst, Dec 25, 2008 IP
  4. jehzlau

    jehzlau Active Member

    Messages:
    301
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #4
    this is exactly what I'm trying to do! Thanks master! yay!!!
     
    jehzlau, Dec 25, 2008 IP