Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post

    PHP dynamic titles

    Hello, I need help in dynamic titles. I'm buliding a CMS and I have structure in which the news function is going after body tag, so I can't give a title variable to <title></title>.
    So what to do?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Could you grab the title from the url?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Jan 2008
    Location
    At home :p
    Posts
    39
    Thanks
    7
    Thanked 1 Time in 1 Post
    How? I usually use just id-s in url (site.com?id=1)
    Last edited by M.W.S.; 05-18-2008 at 09:16 PM. Reason: Grammatical error :D

  • #4
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    842
    Thanks
    15
    Thanked 9 Times in 9 Posts
    If you have a complete header that you include to all the files you can add an if-else (or catch-switch) statement to echo out a header depending on the page id.

    PHP Code:
    <?php
    $titlePrefix 
    "SiteNews";
    if(
    $_GET["id"]==1) {
       
    $title "News";
    }
    elseif(
    $_GET["id"]==2) {
      
    $title "Downloads";
    }
    $newTitle $titlePrefix." :: ".$title;

    //You can output the title from php depending on where you have this code located.
    //Or you can output it in the html as below.
    echo "<title>$newTitle</title>";

    ?>

    <title><?php echo $newTitle?></title>
    Thus when you visit site.php?id=1 the page title should be "SiteNews :: News".
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #5
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    You might want to rethink your file structure.

    If you load your page in a buffer, and then load your template, all of your page variables could be available to your template..

    I wrote up a little template system tutorial that illustrates something similar: Simple Template System Tutorials
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    We had a specific thread on this, see Dynamic <title></title> depending on page
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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