Log in

View Full Version : dynamic title per which statement



xcoaster1
07-03-2008, 07:00 PM
I have a page that uses several if and elseif statements and I would like to adjust the title per what if/elseif statement is served.

Is there anyway to perform this using a variable?

Nile
07-03-2008, 07:51 PM
All you would need to do is something like this:


<?php
$varTitleDetermind = "Hello";
if($varTitleDetermind != "GoodBye"){
$varTitleDetermind = "Hello, your IP is: ".$_SERVER["REMOTE_ADDR"];
}
else {
$varTitleDetermind = "Goodbye ".$_SERVER["REMOTE_ADDR"];
}
echo "<title>".$varTitleDetermind."</title>";
?>

And then you can switch that around to be completely random:


<?php
$varTitleDetermind = rand(0,1);
if($varTitleDetermind){
$varTitleDetermind = "This title is displaying because the \$varTitleDetermind is true";
}
else {
$varTitleDetermind = "This title is displaying because the \$varTitleDetermind is false";
}
echo "<title>".$varTitleDetermind."</title>";
?>

xcoaster1
07-03-2008, 08:11 PM
so if im calling the page with a $_GET where the variable is passed via the URL, I can use something similar to determine the title of the page.

Each variable will return a different set of information, so for the year search, I would want the page title to list year and the page info and for the status, it would show active posts/page in the title.



if ($year >= "2003") {
print table

}elseif ($status == "1") {
print table

}else{
print info

Nile
07-03-2008, 08:17 PM
Well, it should be this:


if ($year >= "2003") {
print "table";

}elseif ($status == "1") {
print "table";

}else{
print "info";
}

But, you've got the idea. :)