Results 1 to 2 of 2

Thread: Need Help: PHP for dynamic page titles

  1. #1
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help: PHP for dynamic page titles

    I've read other posts on here and have tried to simplify the code, but am having problems:

    I've got a page - index.php - within that page is a hard coded header & footer with a php function that calls up another page - for example: default.php

    Header
    default.php
    Footer

    No problems...except I'd like the page titles to reflect the content from default.php

    I tried by putting this in the <head> tag of index.php:
    HTML Code:
    <title><?php echo($title);?> - MyFantasticWebPage.com</title>
    And putting this in default.php:
    PHP Code:
    <?php
    $title 
    "Casino Chair";
    ?>
    but it didn't work....can some steer me in the right direction?
    My actual page example is here: http://www.fiberartfurniture.com/col...php?c=LE0706JC

    Thanks
    --bp

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    In order for your above code to work, you need to call default.php first before calling you can echo the variable $title. The reason for this is because you need to define the variable (in this case, $title) before you can echo it. In index.php, is the header and footer in a variable, function, or some other sort of item that can be called after default.php is included? If not, you may want to think about doing it this way instead of the way you are currently doing it.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •