tothemax Posted August 28, 2007 Share Posted August 28, 2007 Hey everybody: What I'm trying to do is have a different title per article written on my website. The way the site is run now, the server calls on an include file, but the browser still reads it as the title for the index.php. Any ideas on how to fix this problem? Regards. Quote Link to comment https://forums.phpfreaks.com/topic/67139-changing-titles-with-php/ Share on other sites More sharing options...
Asperon Posted August 28, 2007 Share Posted August 28, 2007 some code please it depends on what is in the include file and what is in the index file Quote Link to comment https://forums.phpfreaks.com/topic/67139-changing-titles-with-php/#findComment-336720 Share on other sites More sharing options...
MadTechie Posted August 28, 2007 Share Posted August 28, 2007 this is a HTML issule the "code" would be <title>the Title</title> Quote Link to comment https://forums.phpfreaks.com/topic/67139-changing-titles-with-php/#findComment-336721 Share on other sites More sharing options...
Asperon Posted August 28, 2007 Share Posted August 28, 2007 yes but the include file would be what I want to see Quote Link to comment https://forums.phpfreaks.com/topic/67139-changing-titles-with-php/#findComment-336723 Share on other sites More sharing options...
tothemax Posted August 28, 2007 Author Share Posted August 28, 2007 this is a HTML issule the "code" would be <title>the Title</title> Yeah I've tried this. What I essentially want is the code <title>xyz</title> to override the actual title of index.php. Quote Link to comment https://forums.phpfreaks.com/topic/67139-changing-titles-with-php/#findComment-336727 Share on other sites More sharing options...
MadTechie Posted August 28, 2007 Share Posted August 28, 2007 your need to do something like this. JS echo "<script language='javascript'>document.title = 'NewTitle';</script>"; or PHP/HTML 1. create a header file (header.php) <?php function newheader($title){ if(empty($title)) { $title="default page title"; } echo "<html>"; echo "<head>"; echo "<title>$title</title>"; echo "</head>"; } ?> 2. add at the top of your affected files <?php require_once('newheader.php'); newheader("TheTitle");?> Quote Link to comment https://forums.phpfreaks.com/topic/67139-changing-titles-with-php/#findComment-336734 Share on other sites More sharing options...
saucy Posted August 28, 2007 Share Posted August 28, 2007 I'm the person that put tothemax's site together. I'm not that proficient with PHP, not a novice, but not an expert either. I developed the site using PHP includes. <?php if ($area) {include("content_includes/$area.inc"); } ?> $area is defined at the top of index.php: <?php if ($_GET['area']) { $area = $_GET['area']; } else { $area = "home";} ?> The dilemma is that search engines aren't too friendly with includes, so we changed the pages dynamically through the htaccess file. Which worked alright, but the title section only displays what is on the index.php page. Is there a way to call the section title, in each include file, to the title tag in the head section of index.php? I hope I haven't confused any of you. I think I've confused myself. Quote Link to comment https://forums.phpfreaks.com/topic/67139-changing-titles-with-php/#findComment-336737 Share on other sites More sharing options...
tothemax Posted August 28, 2007 Author Share Posted August 28, 2007 You rule! I'll test these methods out and let you know how it worked. Thanks so much. your need to do something like this. JS echo "<script language='javascript'>document.title = 'NewTitle';</script>"; or PHP/HTML 1. create a header file (header.php) <?php function newheader($title){ if(empty($title)) { $title="default page title"; } echo "<html>"; echo "<head>"; echo "<title>$title</title>"; echo "</head>"; } ?> 2. add at the top of your affected files <?php require_once('newheader.php'); newheader("TheTitle");?> Quote Link to comment https://forums.phpfreaks.com/topic/67139-changing-titles-with-php/#findComment-336739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.