Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2006
    Location
    Greece
    Posts
    194

    PHP and Dynamic <head><title>

    Hello people.

    I designed a website using isset for exploring it.

    Example of index.php:
    Code:
    <?php
    include_once("menu.php");
    include_once("functions.php");
    ?>
    I got a static menu file something like this:
    menu.php:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7" />
    ...
    ...
    <title> static title here </title>
    ...
    ...
    link1, link2, link3, linkX
    ...
    and the functions.php which loading all the rest:
    functions.php:
    Code:
    <?php
    
    if(isset($_GET['something'])){
     include("afile.php");
    }
    
    elseif(isset($_GET['about'])){
     include("about.php");
    }
    ...
    ...
    etc
    So if someone type a www.domain.com/?about after the already
    included menu, the file about.php will be included.

    I tried to make this work:
    eg after the isset to set a $title=something related

    and in the menu.php which have the <title> to add:
    Code:
    <title><?php echo $title ?> </title>
    but it didnt worked.
    A friend told me that this should be BEFORE the menu.php
    but I cant include functions before menu for logical reasons..
    (I need the menu in the top of course)

    I dont know if I can do this including a second functions like
    php but in the if commands to set a title var only not include.

    And generally I got confused with this.
    Any ideas?

    Regards,
    Chris

  2. #2
    Join Date
    Oct 2006
    Posts
    76
    Don't use a static menu.php with the title tag. In the menu.php, check if the query string (about or whatever) is present - if so, display it within the title tag. If not, display a default title.

  3. #3
    Join Date
    Mar 2008
    Location
    Sheffield, UK
    Posts
    447
    I think this has something to do with the scope of the variables you are using. You might have to make some of them global.
    If we do not plant knowledge when young, it will give us no shade when we are old.
    Lord Chesterfield

  4. #4
    Join Date
    Feb 2006
    Location
    Greece
    Posts
    194
    I dont want to make them global and still I didnt find
    a solution searching all evening...

  5. #5
    Join Date
    Oct 2006
    Posts
    76
    Sorry, didn't read your post carefully enough. Obviously, your menu.php file tries to echo the title.

    The problem is the order in which files are loaded - as far as I know, you can't reference from an earlier loaded file a variable whose value is set later.

    I have a simpler solution. In about.php / other similar pages, insert a javascript function executing on load of the body, that sets document.title = Title of Page

    Let the default title be 'Loading Page...'

    This is a bit messy, but should work.

  6. #6
    Or, my suggestion would be for you to make a default page(as in if no get variable is set change the title, ect. to something) and then make the function page run like thing:
    Code:
    <?php
    if (isset($_GET["something"]))
    {$title=*whatever*;
    include("menu.php");
    include("afile.php");}
    
    else if (isset($_GET["about"])){
    $title="The About Page";
    include("menu.php");
    include("about.php");
    }
    
    else 
    {$title="Home Page";
    include("menu.php");
    include("index.php");}
    The reason its not changing the title ect. is because you can't dynamically change the title of a page through php last time i checked.

Posting Permissions

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