Welcome to WebmasterWorld Guest from 34.204.203.142

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Title tag issue

     
8:11 pm on Oct 15, 2008 (gmt 0)

New User

10+ Year Member

joined:Dec 7, 2007
posts: 7
votes: 0


I inherited a site that doesn't use includes. It uses get and then pulls all the pages from a pages folder. i.e.: if(isset($_GET['Page'])){
$Location = $_GET['Page'];

The only problem I have is that the title is the same on every page. Is there a way to have a unique title for each page?

8:40 pm on Oct 15, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


that depends

>> pulls all the pages from a pages folder

is the title only on a single template or is it in each file?

you need to set it in each file, how would depend on how it does it's thing right now.

12:58 am on Oct 16, 2008 (gmt 0)

New User

10+ Year Member

joined:Dec 7, 2007
posts:7
votes: 0


Thank you for the quick reply! The title is on the index page. I love the way the site looks but the metadata and the titles are all the same so I really need to fix that but since I've only worked with php for about 9 months now I only know includes. I've never seen anything set up this way before.

<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-type" content=
"text/html; charset=us-ascii">
<title>Here is my one and only title</title>

<meta name="keywords" content=
"a bunch of stuff that describes the site but I've been reading that this is pointless">
<meta name="description" content=
"some more stuff">
<meta name="author" content="Me :-)">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" >
<link rel="icon" href="/favicon.ico" type="image/x-icon" >
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" >

<script type="text/javascript">
//<![CDATA[
sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++){
sfEls[i].onmouseover=function(){
this.className+=" sfhover";}
sfEls[i].onmouseout=function(){
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");}}}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//]]>
</script>
</head>

<body>
<div id="Wrapper">
<div id="Header">
<div id="banner">
<a href="index.php" title="Main Page" rel=
"contents"><img src="img/Title.jpg" ></a>
</div>



<?php

//Banner changer based on place
if(isset($_GET['Page'])){
$Location = $_GET['Page'];

switch($Location){
case "1.php":
echo "<div class=\"Banner1\"></div>";
break;
case "2.php":
echo "<div class=\"Banner2\"></div>";
break;
case "3.php":
echo "<div class=\"Banner3\"></div>";
break;
case "4.php":
echo "<div class=\"Banner4\"></div>";
break;
case "5.php":
echo "<div class=\"Banner5\"></div>";
break;
case "6.php":
echo "<div class=\"Banner6\"></div>";
break;
default:
echo "<div class=\"Banner\"></div>";
break;
}
}
else
echo "<div class=\"Banner\"></div>";


?>

<div id="ContentWrapper">
<?php
if(isset($_GET['Page']))
{
$page = "pages/";
$page .= $_GET['Page'];
if(is_file($page))
{
include($page);
}
else
{
include('pages/404.php');
}
}
else
{
include('pages/default.php');
}
?>
</div>

</div>
</body>
</html>

7:58 am on Oct 16, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 7, 2007
posts:103
votes: 0


Maybe you could put the $_GET request at the beginning of the page and create a switch similar to the banner presentation.

Like:

if(isset($_GET['Page'])){
$startPage = $_GET['Page'];

switch($startPage){
case "1.php": ?>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=us-ascii">
<title>Title for Page 1</title>
<?php
break;

And so on.

9:43 am on Oct 16, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 24, 2005
posts:697
votes: 0


Simple!

Do the following

1) Put that HTML into a PHP variable
2) change your title to <title>#TITLE#</title>
3) in the switch statement, replace #TITLE# in variable according to the Location
4) echo that variable's content.

Cool? here is it working
-----------------------------------------------------

<?php
session_start();

$html='

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-type" content=
"text/html; charset=us-ascii">
<title>#TITLE#</title>

<meta name="keywords" content=
"a bunch of stuff that describes the site but I\'ve been reading that this is pointless">
<meta name="description" content=
"some more stuff">
<meta name="author" content="Me :-)">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" >
<link rel="icon" href="/favicon.ico" type="image/x-icon" >
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" >

<script type="text/javascript">
//<![CDATA[
sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++){
sfEls[i].onmouseover=function(){
this.className+=" sfhover";}
sfEls[i].onmouseout=function(){
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");}}}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//]]>
</script>
</head>

<body>
<div id="Wrapper">
<div id="Header">
<div id="banner">
<a href="index.php" title="Main Page" rel=
"contents"><img src="img/Title.jpg" ></a>
</div>
';

//Banner changer based on place
if(isset($_GET['Page'])){
$Location = $_GET['Page'];

switch($Location){
case "1.php":
$html.= "<div class=\"Banner1\"></div>";
$html=str_replace("#TITLE#","Title for Page 1",$html);
break;
case "2.php":
$html.= "<div class=\"Banner2\"></div>";
$html=str_replace("#TITLE#","Title for Page 2",$html);
break;
case "3.php":
$html.= "<div class=\"Banner3\"></div>";
$html=str_replace("#TITLE#","Title for Page 3",$html);
break;
case "4.php":
$html.= "<div class=\"Banner4\"></div>";
$html=str_replace("#TITLE#","Title for Page 4",$html);
break;
case "5.php":
$html.= "<div class=\"Banner5\"></div>";
$html=str_replace("#TITLE#","Title for Page 5",$html);
break;
case "6.php":
$html.= "<div class=\"Banner6\"></div>";
$html=str_replace("#TITLE#","Title for Page 6",$html);
break;
default:
$html.= "<div class=\"Banner\"></div>";
$html=str_replace("#TITLE#","Title for Default Case Page",$html);
break;
}
}
else
$html.= "<div class=\"Banner\"></div>";

echo $html;

?>

<div id="ContentWrapper">
<?php
if(isset($_GET['Page']))
{
$page = "pages/";
$page .= $_GET['Page'];
if(is_file($page))
{
include($page);
}
else
{
include('pages/404.php');
}
}
else
{
include('pages/default.php');
}
?>
</div>

</div>
</body>
</html>

9:52 am on Oct 16, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Whatever you do for the title element, do the same for the meta description.
11:58 am on Oct 16, 2008 (gmt 0)

New User

10+ Year Member

joined:Dec 7, 2007
posts:7
votes: 0


THANK YOU BOTH SO MUCH! I'll make the changes to the site :-D :-D