defeated Posted March 18, 2008 Share Posted March 18, 2008 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? ??? Link to comment https://forums.phpfreaks.com/topic/96770-really-basic-stuff-may-not-be-a-php-solution/ Share on other sites More sharing options...
papaface Posted March 18, 2008 Share Posted March 18, 2008 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. Link to comment https://forums.phpfreaks.com/topic/96770-really-basic-stuff-may-not-be-a-php-solution/#findComment-495214 Share on other sites More sharing options...
defeated Posted March 18, 2008 Author Share Posted March 18, 2008 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). Link to comment https://forums.phpfreaks.com/topic/96770-really-basic-stuff-may-not-be-a-php-solution/#findComment-495266 Share on other sites More sharing options...
defeated Posted March 18, 2008 Author Share Posted March 18, 2008 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. Link to comment https://forums.phpfreaks.com/topic/96770-really-basic-stuff-may-not-be-a-php-solution/#findComment-495331 Share on other sites More sharing options...
Jeremysr Posted March 18, 2008 Share Posted March 18, 2008 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> Link to comment https://forums.phpfreaks.com/topic/96770-really-basic-stuff-may-not-be-a-php-solution/#findComment-495337 Share on other sites More sharing options...
defeated Posted March 18, 2008 Author Share Posted March 18, 2008 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. :-\ Link to comment https://forums.phpfreaks.com/topic/96770-really-basic-stuff-may-not-be-a-php-solution/#findComment-495339 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.