Results 1 to 8 of 8

Thread: Managing Title Tag with PHP

  1. #1
    Join Date
    Oct 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Managing Title Tag with PHP

    Can someone explain how to manage the title tag with PHP?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What do you mean? You can echo data inside the <title> tag just like any other tag.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yeah, like if my title is "This is my Webpage about _________" php would control the blank part pulling from some variables or somethin

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <title>This is my Webpage about <?php echo($title);?></title>
    ... where $title is the variable to put in.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    May 2005
    Location
    Hawaii
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I would recommend that you use the define function.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Not necessarily... s/he may wish to override it in an include.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    May 2005
    Location
    Hawaii
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    <?php define ('TITLE''Page Title Here'); 
    //requre the header file      
    require('require/header.php');  
    //rest of code here

    //require the footer
    require('require/footer.php'); ?>
    then you replace the title tags in require/header.php with:
    PHP Code:
    <title><?php if (defined ('TITLE')) {
                        print 
    TITLE;
                    } else {
                        print 
    'Site Title Not Set.';
                        }
            
    ?></title>

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes, but what about:
    PHP Code:
    <?php define ('TITLE''Page Title Here');

    // Start output buffering
    ob_start();
    // Require the body, which will (try to) set a different title for each page
    require('require/body1.php');
    $body ob_get_contents();
    // End output buffering
    ob_end_clean();

    //require the header file
    require('require/header.php');  

    echo(
    $body);

    //require the footer
    require('require/footer.php'); ?>
    Then s/he can't define the title in the body, which is likely to change, and thus likely to set the title.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh 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
  •