Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Page Titles

  1. #1
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default Page Titles

    So when using a dynamic page link like below
    PHP Code:
    <a href='index.php?page=blah'
    How would you get a SEO friendly page title dynamically for the incoming page without setting a specific array on the index.php page checking the incoming page name from the GET variable.

    The problem I find is that almost always the included page is outputted well after the <head> of the page so if you had set the page title on the incoming page it still won't work cause the title has already been rendered in the browser before the included page is rendered.

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Oh also without doing this with a database.

  3. #3
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I dont understand why you cant use GET.

    See:
    http://www.jemcon.org/process_script...p?page=Kit Kat
    or
    http://www.jemcon.org/process_script...page=Milky Bar
    or
    http://www.jemcon.org/process_script...ar of all time

    Put anything for the $page variable in the URL and it can print to the title tag.

    Here's the code for my test page:
    PHP Code:
    <?php
    $title 
    $_GET['page'];
    ?> 
    <!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"> 
    <head> 
    <title><?php echo $title ;?></title>
    </head> 
    <body>
    <h1><?php echo $title ;?></h1>
    </body>
    </html>
    Is that not something you can expand on?
    Last edited by Beverleyh; 07-28-2010 at 03:00 PM. Reason: better grammar

  4. #4
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Ok, where are you defining the text that is being displayed in the page title. I assume it's defined on the incoming page, so are you making a variable on that page or are you saving the file name as the page title you want displayed? Show me more please

  5. #5
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Its just the text in the URL after the '=' sign. Same principle as your example where you put '=blah' - it will be passed to the URL then GET takes it, assigns it to the variable $page, and its printed wherever you want in your web page, be it in the body or title tag.

  6. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Sorry, I keep saying the $page variable - I mean the $title variable

  7. #7
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    What you could do is just create two variables on those included pages, one for the title and one for the content. Then include them on the top of your index page and use the variables where you like in the output.
    This was an answer on another forum I posted on and it's pretty much the kind of answer I think I was looking for. I hadn't thought about making the entire content on the included page a variable and then calling it when and where I needed on the main page. The only thing I can think that might be an issue is if the page is really full of content, the variable would be pretty large too on the main page until it was used, so would that slow down page load or anything else bad?

  8. #8
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I hadn't thought about making the entire content on the included page a variable and then calling it when and where I needed on the main page. The only thing I can think that might be an issue is if the page is really full of content, the variable would be pretty large
    Thats not what the example I gave does - you dont appear to be understanding what I'm saying.
    Just look at the URL (the address bar) of the page once its called. You can pass anything after the = sign in the URL only - nothing to do with content on the page.

    Try it by putting your cursor at the end of any of the example URL's I gave then delete everything up to the = sign and type anything else >> refresh the page and that's what GET uses for the title.

    Here - to make it easier, I've added a load of Lorem Ipsum to show that content has no bearing on the passed variable. I've also created some links to illustrate what you wanted in your original post. Notice how its always the same title.php page that's being used - the fact that its called title.php is irrelevant - and see that its your index.php?page=blah example. Revised page: http://www.jemcon.org/process_scripts/test/title.php
    There's no title initially because nothing is passed to GET from the URL. As soon as you click on the links, text after the "=" is passed to "$title" and it can be echo'd on the page.

    The code for the links is just:
    Code:
    <ul>
    <li><a href="title.php?page=About Us">About Us</a></li>
    <li><a href="title.php?page=Contact Us">Contact Us</a></li>
    <li><a href="title.php?page=Our Services">Our Services</a></li>
    <li><a href="title.php?page=More Information">More Information</a></li>
    <li><a href="title.php?page=Terms and Conditions">Terms and Conditions</a></li>
    </ul>
    Last edited by Beverleyh; 07-28-2010 at 07:15 PM. Reason: spelling corrected

  9. #9
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Ah ok, now I understand your concept. But I typically use this code to verify the page that is being called
    PHP Code:
    if ($page){
                            if (!
    strpos($page,".")&&!strpos($page,"/")){                        
                        
    $path "$page.php";
                        if (
    file_exists($path)){
                        include (
    "$page.php");
                        }
                        else{
                            echo 
    "That page does not exist<br/><br/><a href='#' onclick='history.go(-1)'>Go Back To Previous Page</a>";
                        }
                        }
                    } 
    But I suppose I could (in you type of example) just add a &title=blahblah and GET that for the title, which I suppose works good to since the link has to be defined somehow so adding that would be easy enough. Cool

  10. #10
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Your welcome.

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
  •