I want to create a code for titles which says "if this page is called "thisfile.html" then $title="Whatever Description Fits"
Any ideas?
Thanks!
What should I use for this?
Moderator: General Moderators
Try this....
Code: Select all
<?php
switch($HTTP_SERVER_VARSї'PHP_SELF']){
case "/whatever.html":
$title = "hey!";
break;
case "/anotherpage.html":
$title = "page #2";
break;
case "/index.html":
$title = "Index";
break;
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
An alternative is to use arrays:
So when you want to insert the title:
Or you can put all the information about the page in a database...
Mac
Code: Select all
$titles = array(
'whatever.html' => 'hey!',
'anotherpage.html' => 'page #2',
'index.html' => 'index'
);Code: Select all
echo '<title>'.$titlesї$page].'</title>';Mac
It's a bit over the top but on some of my larger sites I like to keep all of that stuff in a mysql database and pull it all out before constructing the page. A bit of code for you as an example taken straight from one of my sites
I run this at the top of the page before everything except cookies.
It's a bit server heavy to do this sort of thing but I like having good easy access to all of these things so I can change them to keep up with whatever the current thinking on search engine optimisation is.<?php
if ($page == "") {
$page='home';}
include "connection.php";
$initialquery = "SELECT * FROM tblpage AS t2 ";
$queryconditions = "WHERE t2.gpName LIKE \"".$page."\" ";
$orderresults = "ORDER BY t2.gpName";
$getresults = $initialquery." ".$queryconditions." ".$orderresults;
$result = mysql_query($getresults, $db_connection);
$num_results = mysql_num_rows($result);
if ($num_results == "") {
echo "There has been an error in the site please try and refresh your browser, if the problem persists please contact customer services";
}else {
$info = mysql_fetch_array($result);
}
//Set values from those in the database
$Pagecode = stripslashes($info["gpPage"]);
$PageName = stripslashes($info["gpName"]);
$Title = stripslashes($info["gpTitle"]);
$Keywords = stripslashes($info["gpKeywords"]);
$Desc = stripslashes($info["gpDescription"]);
$Navgroup = stripslashes($info["gpNavgroup"]);
$Navlinkname = stripslashes($info["gpNavlinkname"]);
$Header = stripslashes($info["gpHeader"]);
$Main = stripslashes($info["gpMain"]);
$Footer = stripslashes($info["gpFooter"]);