Page 1 of 1

What should I use for this?

Posted: Thu Jun 20, 2002 6:40 pm
by Jim
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!

Posted: Thu Jun 20, 2002 8:49 pm
by Peter
Try this....

Code: Select all

<?php

switch($HTTP_SERVER_VARS&#1111;'PHP_SELF'])&#123;
    case "/whatever.html":
        $title = "hey!";
        break;
    case "/anotherpage.html":
        $title = "page #2";
        break;
    case "/index.html":
        $title = "Index";
        break;
&#125;

?>

Posted: Fri Jun 21, 2002 2:34 am
by twigletmac
An alternative is to use arrays:

Code: Select all

$titles = array(
    'whatever.html' => 'hey!',
    'anotherpage.html' => 'page #2',
    'index.html' => 'index'
);
So when you want to insert the title:

Code: Select all

echo '<title>'.$titles&#1111;$page].'</title>';
Or you can put all the information about the page in a database...

Mac

Posted: Fri Jun 21, 2002 8:04 am
by e+
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
<?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"]);
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. :wink: I run this at the top of the page before everything except cookies.

Posted: Fri Jun 21, 2002 8:10 am
by Kriek
That could come in handy for template design.
I think I did something very similar.

Posted: Fri Jun 21, 2002 11:35 am
by e+
It's not the newest bit of code I've done and I'd advice you edit out lots of " and put in some ' in their place, no point making the server work too hard. :wink: