SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Location
    Australia
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php title script

    looking for a script that i can insert say

    $title=pagetitle
    then include title.php

    and the title of the actual webpage changes with the $title variable because I have many webpages using includes and I need variables for my titles.

    if that makes sense.

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $title 
    "whatever"//You can determine how to get this
    ?>
    <html>
    <!-- header tags go here -->
    <title><?php echo $title ?></title>
    </html>
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If title.php is being included, then you'll have to declare $title to be global like this:

    PHP Code:
    global $title
    echo "<title>$title</title>"

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Location
    Australia
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by siteguru
    PHP Code:
    <?php
    $title 
    "whatever"//You can determine how to get this
    ?>
    <html>
    <!-- header tags go here -->
    <title><?php echo $title ?></title>
    </html>
    that doesnt work

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Location
    Australia
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if i make title.php just have the text "yoyo"

    then do this in header.php: <?php include('title.php'); ?>

    I get it working.

    But I need the title to by different for each page.

    Perhaps It is something to do with the page structure as it goes like this.

    index.php -

    include header.php
    <indext content>
    include footer.php

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just declare $title before you include header.php.


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
  •