Dynamic Titles

Discussion in 'PHP' started by wvcaudill2, Jun 11, 2009.

  1. #1
    Hello, im trying to make the CMS system im using more SEO friendly by giving each page it's own title. Right now, the system assigns all pages the same general title. I would like to use PHP to discertain which page is being viewed and in turn, which title should be used.

    I have put in the title tags the variable "$title". As for the PHP im using, I scripted the following:

    $url = "http://'.$_SERVER['SERVER_NAME']''.$_SERVER['REQUEST_URI']'";
    switch ( $url )
    {
    	default:
    		$title = "Photoshop tutorials, Flash tutorials, and more! Newtuts Tutorial Search";
    		break;
    
    	case "$config[HTTP_SERVER]help.php" :
    		$title = "Newtuts Help";
    		break;
    }
    PHP:
    Right now, im getting this error:
    Can someone please help me with this?
     
    wvcaudill2, Jun 11, 2009 IP
  2. HorseGalleria

    HorseGalleria Peon

    Messages:
    91
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    
    $url = "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
    switch ( $url ) {
    
        case "{$config['HTTP_SERVER']}help.php" : $title = "Newtuts Help"; break;
      
        default : $title = "Photoshop tutorials, Flash tutorials, and more! Newtuts Tutorial Search";
    }
    
    Code (php):
     
    HorseGalleria, Jun 11, 2009 IP
  3. wvcaudill2

    wvcaudill2 Peon

    Messages:
    176
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Im not getting anymore errors, but its still not working. You can see the site im trying to implement this on here: http://www.newtuts.com
     
    wvcaudill2, Jun 11, 2009 IP
  4. optimeramera

    optimeramera Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <title>echo $title</title>

    Can you post the php-code you use to echo out the $title-var?

    i.e
    <title><?php ... ?></title>
     
    optimeramera, Jun 12, 2009 IP
  5. makaleus

    makaleus Peon

    Messages:
    264
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <html><head>
    <title> echo $v['title'];
    </title>
     
    makaleus, Jun 12, 2009 IP
  6. wvcaudill2

    wvcaudill2 Peon

    Messages:
    176
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This is what it looks like:
    <title>echo $title</title>
    PHP:
     
    wvcaudill2, Jun 12, 2009 IP
  7. uselessguy

    uselessguy Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Right code:

     
    uselessguy, Jun 12, 2009 IP
  8. wvcaudill2

    wvcaudill2 Peon

    Messages:
    176
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Nope, that didnt change anything. In the title it still says "echo $title"
     
    wvcaudill2, Jun 12, 2009 IP
  9. mubashirnisar

    mubashirnisar Banned

    Messages:
    2,186
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #9
    <title>echo $title</title> ... where is ";" ?? <title>echo $tilte;</title>
    if it does not work try to close PHP tag "?>" before tiltle tag then try this <title><?php echo $title; ?></title>
    i only know this, I m a beginner ;)
     
    mubashirnisar, Jun 12, 2009 IP
  10. wvcaudill2

    wvcaudill2 Peon

    Messages:
    176
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Still no luck :(
     
    wvcaudill2, Jun 12, 2009 IP
  11. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    if your title is coming up as "echo $title;"
    try <title><?php echo $title; ?></title>
     
    SHOwnsYou, Jun 12, 2009 IP
  12. wvcaudill2

    wvcaudill2 Peon

    Messages:
    176
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Now were getting somewhere! The title is now being displayed as the web page URL. Now we just need to get it to recognize the URL, and assign an actual title. Any ideas?
     
    wvcaudill2, Jun 12, 2009 IP
  13. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    may be easier to just put a "title" column in your database
    put your query at the top..

    for each page put this line in the <head> section: echo "<title>$row[title]</title>";
     
    SHOwnsYou, Jun 12, 2009 IP
  14. wvcaudill2

    wvcaudill2 Peon

    Messages:
    176
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I thought about that, but im using a CMS system, and Im afraid that if I do that it will mess something up. There are very few custom pages that I will need titles for, so I would rather do things the way I had originally planned if possible.
     
    wvcaudill2, Jun 12, 2009 IP
  15. wvcaudill2

    wvcaudill2 Peon

    Messages:
    176
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Anybody got anymore ideas?
     
    wvcaudill2, Jun 13, 2009 IP
  16. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #16
    Looks like I am late to the party. I am going to back up and ask a couple of questions:

    Which CMS system are you using? (Could influence approach).
    Does the CMS system use Smarty or other template engine?
    Are you currently using the Apache URL Rewrite module?
     
    Social.Network, Jun 13, 2009 IP
  17. wvcaudill2

    wvcaudill2 Peon

    Messages:
    176
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Lol, im just glad you came :)

    1. I am using a modified system of TutorialMS
    2. It uses a custom template engine. Basically it includes the config and global files on every page, and then, depending on the page, it includes from the database the right page info.
    3. I am not using any rewrite modules.
     
    wvcaudill2, Jun 13, 2009 IP
  18. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #18
    It appears the title is set and stored in a global variable $glob['title'].

    The page titles follow the pattern below (do you want to modify the highlighted title?):

    $glob['title'] = COMPANY_NAME.' - Index';
    $glob['title'] = COMPANY_NAME.' - Contact Us';
    $glob['title'] = COMPANY_NAME.' - Help';
    $glob['title'] = COMPANY_NAME.' - '.$read_tutorial['title'];
    $glob['title'] = COMPANY_NAME.' - Submit Tutorials';
    $glob['title'] = COMPANY_NAME.' - Tutorials from '.$glob['sourcesite'];
    $glob['title'] = COMPANY_NAME.' - Submit Tutorials';
    $glob['title'] = COMPANY_NAME.' - Browse Tutorials';
    $glob['title'] = COMPANY_NAME.' - '.$glob['cur_cat_name'].' - All';
    $glob['title'] = COMPANY_NAME.' - '.$glob['cur_cat_name'].' - '.$glob['cur_sub_name'];
    $glob['title'] = COMPANY_NAME.' - '.$user['username'].'\'s Profile Page';
    $glob['title'] = COMPANY_NAME.' - Register';
    $glob['title'] = COMPANY_NAME.' - '.$glob['tutorial_out_title'];
    $glob['title'] = COMPANY_NAME;
     
    Social.Network, Jun 13, 2009 IP
  19. wvcaudill2

    wvcaudill2 Peon

    Messages:
    176
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19
    This doesnt seem right. Before I tried setting a dynamic title. The same title was displayed for everything. Why is this?
     
    wvcaudill2, Jun 13, 2009 IP
  20. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #20
    I am using TutorialMS 1.4 as the baseline. Are you using a different version or have you modified the original title algorithm?
     
    Social.Network, Jun 13, 2009 IP