daveoffy Posted November 17, 2008 Share Posted November 17, 2008 I am changing up my site a little more to make it simple to edit but only changing one file. So I have the include for the header and that all works. But I want each page to have a different title. So I tried $title = 'Title Name' under the include file. and set the title to $title and it doesn't work. Does anyone know how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/133133-solved-php-title/ Share on other sites More sharing options...
premiso Posted November 17, 2008 Share Posted November 17, 2008 Some code would be very helpful. Quote Link to comment https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692348 Share on other sites More sharing options...
DeanWhitehouse Posted November 17, 2008 Share Posted November 17, 2008 Have you put the variable above the include? And make sure you arn't overwriting it in the included file. Quote Link to comment https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692389 Share on other sites More sharing options...
cooldude832 Posted November 17, 2008 Share Posted November 17, 2008 This is a common issue of envoking CMS because generally you use a sandwhich principle to include a footer/header around a dynamic content section. The trick to doing this, this is one easy way. 1) Make a separate include_once page called titles which has an array that looks like <?php $titles['index.php'] = "Home Page"; $titles['about.php'] = "About Us"; ?> Include it above your header include and draw your titles of this combined with $_SERVER['PHP_SELF']; Quote Link to comment https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692391 Share on other sites More sharing options...
daveoffy Posted November 17, 2008 Author Share Posted November 17, 2008 Thanks for all the help. I will be sure to try that out after my home work. Quote Link to comment https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692396 Share on other sites More sharing options...
daveoffy Posted November 17, 2008 Author Share Posted November 17, 2008 Where do I put the include_once statment? Also in the <title></title> in the header.php file what do I need to put in there? Quote Link to comment https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692408 Share on other sites More sharing options...
cooldude832 Posted November 18, 2008 Share Posted November 18, 2008 like <?php require_once("titles.php"); require_once("header.php"); ?> In header.php <?php echo "<head>"; echo "<title>Mysite: ".$titles[$_SERVER['PHP_SELF']]."</title>"; echo "</head>"; ?> Should get that title var You could put the titles in the header file but down the line you may say hey lets add DB backend to it and then its already separated and easy to build into it Quote Link to comment https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692418 Share on other sites More sharing options...
daveoffy Posted November 18, 2008 Author Share Posted November 18, 2008 Thank you sooo much. And thanks for the idea of maybe using it in database later on. Quote Link to comment https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692420 Share on other sites More sharing options...
cooldude832 Posted November 18, 2008 Share Posted November 18, 2008 I actually encountered this error in writing my CMS about 6 months ago and it made me restructure my whole process. Mine uses a database to pull everything so what I needed to do was first query for the content and title of the given page and then get the header/footer content then send header-content-footer to the browser for rendering. Once you figure it out its simple but I knocked my head on a wall for a week on making it work how I wanted. Quote Link to comment https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692425 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.