SitePoint Sponsor |
|
User Tag List
Results 1 to 12 of 12
Thread: Dynamic Page Title
-
Jun 18, 2006, 17:12 #1
- Join Date
- Apr 2006
- Location
- Timisoara/Romania
- Posts
- 45
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Jun 18, 2006, 17:47 #2
- 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);
-
Jun 18, 2006, 19:40 #3
- 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.
-
Jun 18, 2006, 19:52 #4
- 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
-
Jun 18, 2006, 21:07 #5
- Join Date
- Apr 2006
- Location
- Timisoara/Romania
- Posts
- 45
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by optl
I mean the english is ok, but don't know the "techincal" details
-
Jun 18, 2006, 21:14 #6
- 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.
-
Jun 18, 2006, 21:19 #7
- 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.
-
Jun 18, 2006, 21:27 #8
- Join Date
- Sep 2005
- Location
- Chicago, IL
- Posts
- 479
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by optl
You run your script, and based on conditions of the page, you BUILD your variable
PHP Code:$content = '<h1>Page Header</h1>';
PHP Code:$content .= '<p>this too, but not that...</p>';
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;
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.
-
Jun 18, 2006, 21:30 #9
- Join Date
- Apr 2006
- Location
- Timisoara/Romania
- Posts
- 45
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
this is to complicated for me
sorry
-
Jun 19, 2006, 03:53 #10
- 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>
PHP Code:<?php
define ('TITLE', "YourSite.com - Homepage");
include_once("pageheader.php");
?>
PHP Code:<?php
define ('TITLE', "YourSite.com - About Us");
include_once("pageheader.php");
?>
Hope it helps.
-
Jun 19, 2006, 17:34 #11
- Join Date
- Apr 2006
- Location
- Timisoara/Romania
- Posts
- 45
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hey, it works. Thanks
-
Jun 11, 2007, 15:57 #12
- 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