Have you ever wondered how sites (like this one) have a different page title for each page?
Here is how you do it:
Lets say you have 3 pages: index.php, about.php and contact.php. You need to have the page include system working so we can use the same variable for the page title changer.
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My website > < ? $page=$_GET['page']; //page title changer
if ($page=="about"){ //if the page you are viewing is about.php it shows "About me" text in the page title
echo "About me"; //shows "About me" text on page title
}elseif($page=="contact"){ //same as above but with contact.php
echo "Contact me"; //same as above but with "Contact me" text on page title
}else{
echo "Home"; //shows "Home" text on page title
}
?></title>
</head>
<body>
<a href="http://www.mywebsite.com">home</a> <!-- Menu link -->
<a href="?page=about">about me</a> <!-- Menu link for about page -->
<a href="?page=contact">contact me</a> <!-- Menu link for contact page-->
< ? $page=$_GET['page']; //include system. loads the file when you click the link
if ($page=="about"){ //if you click the about link it will load about.php
include('about.php'); //it loads about.php inside the index.php
}elseif($page=="contact"){ //same as above but with contact
include('contact'); //same as above but with contact.php
}else{
include('home.php'); //loads home.php if no link is clicked or if did not find any of the links/files above
}
?>
</body>
</html>
Page title changer
Have you ever wondered how sites (like this one) have a different page title for each page?
Here is how you do it:
Lets say you have 3 pages: index.php, about.php and contact.php. You need to have the page include system working so we can use the same variable for the page title changer.
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>My website > < ? $page=$_GET['page']; //page title changer if ($page=="about"){ //if the page you are viewing is about.php it shows "About me" text in the page title echo "About me"; //shows "About me" text on page title }elseif($page=="contact"){ //same as above but with contact.php echo "Contact me"; //same as above but with "Contact me" text on page title }else{ echo "Home"; //shows "Home" text on page title } ?></title> </head> <body> <a href="http://www.mywebsite.com">home</a> <!-- Menu link --> <a href="?page=about">about me</a> <!-- Menu link for about page --> <a href="?page=contact">contact me</a> <!-- Menu link for contact page--> < ? $page=$_GET['page']; //include system. loads the file when you click the link if ($page=="about"){ //if you click the about link it will load about.php include('about.php'); //it loads about.php inside the index.php }elseif($page=="contact"){ //same as above but with contact include('contact'); //same as above but with contact.php }else{ include('home.php'); //loads home.php if no link is clicked or if did not find any of the links/files above } ?> </body> </html>No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.