SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Dynamic Page Title

    Hello,

    I'm having a problem.

    I have a page. The index and every page contains include(pageheader.php) and include footer).

    So everything is working ok. But. I want to create a Dynamic Page Title.
    The Page title is MY PAGE, but when i'm on the "CARS" category i want something like: MY PAGE - CARS. Got my point?

    Do you have any sugestion hot to do this?

    Thanks and sorry for my n00bis

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    define the page variable before you include your header, then have your header echo it out.


    if you find that difficult to do, maybe output buffering would make it easier for you.


    PHP Code:
    ob_start();
    include 
    'header.php';
    $header ob_get_clean();

    $title 'your title';
    echo 
    str_replace('***PAGE_TITLE***'$title$header); 

  3. #3
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the thing is that I must include the "title" after the header. So we woun't se my variable. True?
    My page is like this:

    Page_header.php
    Index.php (or any other paeg)
    page_footer.php

    Page header includes all the heading...andi ndex is only the body, footer has some table + the </body> tag.

  4. #4
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In order to accomplish that you are going to need to run script on the final html before outputing it.
    For my scripts, I create a $content variable which is added to throughout the page. Then at the end of the page, I can just fit the header and footer around the content variable.
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed

  5. #5
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by optl
    In order to accomplish that you are going to need to run script on the final html before outputing it.
    For my scripts, I create a $content variable which is added to throughout the page. Then at the end of the page, I can just fit the header and footer around the content variable.
    I don't really understand your message I mean the english is ok, but don't know the "techincal" details

  6. #6
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your index.php is about to getting data dynamically either from database, or in include file formats... you need to define each title related to the page which is including in index.php... from that place, in header file, you can get the title.

  7. #7
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, if i modify the title in the header, it's ok, but I want a dynamic one. If i'm on page X then I want the X title, if i'm on the Y I want Y title. Normaly, I have X for all the pages.

  8. #8
    SitePoint Evangelist Rodney H.'s Avatar
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by optl
    In order to accomplish that you are going to need to run script on the final html before outputing it.
    For my scripts, I create a $content variable which is added to throughout the page. Then at the end of the page, I can just fit the header and footer around the content variable.
    That is what I do too.

    You run your script, and based on conditions of the page, you BUILD your variable
    PHP Code:
    $content '<h1>Page Header</h1>'
    As the script progresses, you may need to concatenate more onto the content var:
    PHP Code:
    $content .= '<p>this too, but not that...</p>'
    After you figure out the content of the page, you can then DEFINE YOUR TITLE, and include your page structure, whether it exits in one file as a "bootstrap" or in multiple files like a header, navigation, and footer, etc...
    PHP Code:
    if($this == true)
    {
      
    $title 'Page ONE: A';
    }
    else {
      
    $title 'Page ONE: B';
    }

    include(
    'includes/header.php');
    include(
    'includes/footer.php');
    $page $header $content $footer;
    echo 
    $page
    THere are better ways of doing this, but it shows you the general concept of ONE way to approach it...

    The neat thing about figuring out the content first is that you can dynamically define page titles, style sheets, etc... first before/while building your page.

    Hope that helps.

  9. #9
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is to complicated for me
    sorry

  10. #10
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok edit the title tags in your pageheader.php file to this:
    HTML Code:
    <title>
    	<?php if (defined ('TITLE')) 
    	{	
    		print TITLE;
    	}
    	else
    	{	print 'YourSite.com';
    	}?>
    </title>
    and then on your index.php page put this at the top:

    PHP Code:
    <?php 
    define 
    ('TITLE'"YourSite.com - Homepage");  
    include_once(
    "pageheader.php"); 
    ?>
    and then on your about_us.php (for example) page put this at the top:

    PHP Code:
    <?php 
    define 
    ('TITLE'"YourSite.com - About Us");  
    include_once(
    "pageheader.php"); 
    ?>
    If you fail to define a title for a page, the default title of "YourSite.com" will be used for the title tags.

    Hope it helps.

  11. #11
    SitePoint Enthusiast -PET-'s Avatar
    Join Date
    Apr 2006
    Location
    Timisoara/Romania
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey, it works. Thanks

  12. #12
    SitePoint Member
    Join Date
    Oct 2006
    Location
    Florida
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Old Topic but i have to post, just to say Thank you so much for this, THANKS THANKS THANKS. This made my day!


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
  •