I have a problem with the page titles, I have thought about using “<title>Site - <? echo $_GET['page']; ?></title>” and to use the URL “?page=Website%20Design” but I’d rather not. What can I do?
How are you getting to the page? If it's one page that a user clicks a link (thus the URL '?page=Web%20Design') then you could instead use a cookie, or a session. That way it gets rid of the need to pass the variable through the URL.
If I'm completely misunderstanding your question, I blame Warcraft and the obsession that requires me to stay up late.
Jaelan
"I killed the world once! You can too, if you try hard!"
--Lews Therin,
Robert Jordan's "The Wheel of Time"
Yea, I’ve already tried that and I know it displays Website Design.
What I want to know is how I can add an extra array so when “domain.com/index.php?page=website_design” is requested it can display anything like “Website Design Page” and so on for all the pages.
What I use for the sites I manage is the following:
I've simiplified out all the meta, encoding info, doc types, etc.. I have it setup to display a different image on differents page and I've removed that aswel for the example so... anyway....
3 Files - head.inc.php - containing all the header information foot.inc.php - containg all the footer information pagename.php - the contentm plus the calls to include the head and foot files.
I'm sure you can follow what it's doing, setting the variable when the page is requested, and then passing it on to the header file which then adds - BA Silver Wing Sailing Club to the end of it, so that's on every page, and you can change the first bit for each page by changing the $pgname string, so you end up with titles like the following for example:
Welcome - BA Silver Wing Sailing Club
Join Us - BA Silver Wing Sailing Club
Contact - BA Silver Wing Sailing Club
If a title isnt set, it uses the 'Default Title' instead.
Which you can have as an echo, like I put in above, or you can use like I do on some of my sites: (date($format)); which sets the date.
You can add all sort of extra things to it, like I also have
What this does, it allows me to have a different image at the top of every page, by setting the name of the image in the image directory, history.jpg, main.gif, contact.jpg, location.gif, etc... But if I set $imgname string as the text - runrandom then it runs the random image script and displays a random header image on that page.
I hope some of that makes some sort of sense.
Gav
Last edited by GavinPearce; 12-04-2004 at 11:53 AM.
Have I really been coming here for 6 years? You would have thought I would have learnt something by now!
If you don't have a lot of pages you want to administer the titles of, you could just delete the <title> tag on your index.php page and instead put it on your included pages. Index.php will use that <title> tag. Like this:
index.php has no <title> tag
test.php has a <title> tag ( <title>Test</title> )
beer.php has a <title> tag ( <title>Beer</title> )
index.php?page=test will have the title Test
index.php?page=beer will have the title Beer
But, if you have a few hundred pages to maintain, gavinnet's suggestion makes perfect sense.
### functions.txt ###
function header($title)
{
echo <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'><head><title>$title</title>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
<LINK REL=stylesheet HREF='style.css'>
</head>
<body>
EOD;
}
function footer()
{
echo "</body></html>";
}
PHP Code:
### some_page.php ###
<?php
include "functions.txt";
header("This Page's Title");
?>
<h1>This Page's Heading</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum</p>
<?php
footer();
?>
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Something I forgot to add is that I tend to use head.inc.php instead of just ending it with the .inc and then I echo it out.
This doesn't really achieve anything except it stops you viewing the contents of head.inc.php direct, which does nothing really except people can't find out what info is teh page info and what info is the header info.
Stupid I know but just seems to me to be better than head.inc
lol I'll shut up now.
Have I really been coming here for 6 years? You would have thought I would have learnt something by now!
Thanks for your suggestions, but I decided not to use the variable URL (?page=) instead I’m using separate PHP pages which include the header after the title tag:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Page! - Test</title>
<?php require("inc/header.php"); ?>
Bookmarks