Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Page title from include php file??
Old 05-09-2009, 04:55 PM Page title from include php file??
Experienced Talker

Posts: 49
Location: Pula, Istra, Croatia
Trades: 0
I want that my site has different title on almost every page.
How do I get page title from included php file...

I have an index.php file that inlcudes header, content and footer page...how do I pull page title from content.php??
shile is offline
Reply With Quote
View Public Profile Visit shile's homepage!
 
 
Register now for full access!
Old 05-09-2009, 05:29 PM Re: Page title from include php file??
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
You can get a title from the directory your page is in. For example in the header include the function

<?php
$page = end(explode('/' , $_SERVER['SCRIPT_NAME']));
$title = str_replace('.php', '', $page);
$title = ucwords($title);
echo '<title>You Page | ' . $title . '</title>';
?>

That should give you a different title for every page.

Then name your directories like this 'your article.php' and the title will be
Your Page | Your Article

Hope this helps
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Old 05-09-2009, 06:35 PM Re: Page title from include php file??
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Or simpler, create a variable that will hold the page name in eache page you want custom name.
And when you include the header, check for it

page1.php:
PHP Code:
$title="my super duper home page";
...
include(
"header.php"); 
header.php:
PHP Code:
$title=isset($title)?$title:"default super boring title for a not so boring page";
echo
"<title>$title</title>"
That way, if header.php found a variable named "$title" it will use it content.
If not, it will use a default title.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Page title from include php file??
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44638 seconds with 12 queries