Varying Title Tags from Homepage vs InnerPages Using PHP?

Discussion in 'PHP' started by Entrep, May 14, 2008.

  1. #1
    Hi all

    I have a website that runs on PHP.

    In the title tags in the header I have:

    <title>Website.com - Tagline for site - Variable</title>

    This is great for the home page, but for inner pages I just wouldn't mind it saying:

    <title>Website.com - Variable</title>

    So my question is: Is there some code (maybe an if statement?) that I can use so that on the homepage it will use one set of title tags, and on other pages it will use another set of title tags?

    Cheers!
     
    Entrep, May 14, 2008 IP
  2. wdstuff54

    wdstuff54 Well-Known Member

    Messages:
    639
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #2
    You could set a var on the index page to true. Then check the status of the var and if it is true then display the tagline.

    Does that help?
     
    wdstuff54, May 14, 2008 IP
  3. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #3
    This code checks if requested page is homepage
    
    if ($_SERVER['REQUEST_URI']!="/") {
    // here you can assign necessary title
    }
    
    PHP:
    or
    
    if ($_SERVER['REQUEST_URI']!="/" || $_SERVER['REQUEST_URI']!="/index.html") {
    }
    
    PHP:
    If you have two addresses for homepage.
     
    AsHinE, May 14, 2008 IP
  4. venetsian

    venetsian Well-Known Member

    Messages:
    1,105
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    168
    #4
    I'm not sure how you're coding your pages, but if you use one page for example index.php?page=index and then you have index.php?page=contact then the statement should be something like that:

    <?php
    switch($page) {
    case "index" : {
    $title="blah blah blah";
    $description="double blah";
    break;
    }
    case "contact" : {
    $title="contact blah blah";
    $description="double contact blah";
    break;
    }
    }
    ?>

    othewise you can just set $page=$_SERVER['REQUEST_URI'];
    and replace the conditions with the correct url

    Venetsian.
     
    venetsian, May 14, 2008 IP
  5. Entrep

    Entrep Well-Known Member

    Messages:
    588
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Hmm thanks guys

    I couldnt get them working though, the page would just be blank!
     
    Entrep, May 15, 2008 IP