Jump to content

Really basic stuff.... may not be a php solution


defeated

Recommended Posts

Hi, This is about <title> tags.

The Problem: How to have a different title tag on each page of my site.

The Complication: I have a separate Header.php file which I use "include" to attach to my page. This file has most of my page structure in it ("include('footer.php') has the rest).  I have been using <table> as the structure for the site so each page is just a <td> cell in the structure... not that I realised it to start with.  I was treating each page as a full page complete with head section..... it worked but it's a million miles from correct syntax.  I was thinking I could use "switch" to change the title depending on the page but there is a futher problem. I have dynamic pages based on a mysql db. These pages could potentially change several times a day and keeping up with the changes with my switch switch is not practical. I'm looking at changing the site structure to <div> but I am just at the very first stages of finding out how <div> works. Am I wasting my time with that or am I going in the right direction?  Is there any difference when it comes to the <head> and <title> in particular?  ???

Something like:

<?php

//header code

//db credentials above

$gettitle = mysql_query('SELECT `title` FROM `pages` where `filename`="'.basename($_SERVER['PHP_SELF']).'"');

list($_title) = mysql_fetch_array($gettitle);

echo '<title>'.$_title.'</title>';
//more code
?>

Using a database and the filename to do the title.

Ok, I think I wasn't clear enough about the db.  It doesn't have any individual page details... rather they are job descriptions that I then fit into a template. At present the title for those pages is a mixture of text and details from the db eg <title>Job Details for <?php echo $jobtitle ; ?></title> where $jobtitle is the result of a MySql query. But not all my pages are from the database for example my home page, about page, contact page. These would have to have another solution. Maybe I have to use a mixture of both methods. (get and switch).

 

Surely there is a simple way of doing this? Otherwise why would anybody bother separating the header and footer. The thing is I will have to do the same for the description and keywords..... it's looking like a lot of hassle for the luxury of having my header and footer separate... I'm beginning to wonder what the advantage is of having them separate.

I just do something like this on each page:

 

include 'header-php.php';

// Get job title from database here

$page_title = "Job Details for $jobtitle";
include 'header-html.php';

 

header-php.php would have all the php code like functions and connecting to mysql and sessions. header-html.php would be mostly HTML and would put the title like this:

 

<title><?php echo $page_title; ?></title>

I like that idea. It means I could write a different case for each page. The dynamic pages are based on only two templates currently so I would only need 6 different cases for the site. each case for the dynamic pages could include your suggestion and variations of. Still a bit of a hassle compared to writing the title on each page like I was. But anything for valid code on the site. :-\

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.