IF Then Display Text on Homepage Only

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

IF Then Display Text on Homepage Only

Post by Danielc1234 »

Hi all, new to php. I am trying to put a command in my header that will display some text only if it is the home page or "/" page.

<?php if($this->getRequest()->getRequestUri() == '/') { /* show it */ } ?>

This is what I have so far, but not working correctly. Can some one tell the full php code to use if the page is the home page do this <div class="vtop"><h1 align="center">DOG CAR SEATS | DOG CAR SEAT</h1></div> and if not the home page, do nothing at all?

Thanks in advance
GreenCore
Forum Newbie
Posts: 5
Joined: Thu Dec 18, 2008 6:53 am

Re: IF Then Display Text on Homepage Only

Post by GreenCore »

Maybe this will help:

Code: Select all

<?php
    if ($_SERVER["REQUEST_URI"] === "/"){
            //main root website (also for subdomains)
            //Your Code
            echo '<div class="vtop"><h1 align="center">DOG CAR SEATS | DOG CAR SEAT</h1></div>';
    } else {
            //Your Code
    }
?>
Good luck!
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Re: IF Then Display Text on Homepage Only

Post by Danielc1234 »

GreenCore, Thanks it worked great!!!!!
Post Reply