TCombs Posted February 17, 2011 Share Posted February 17, 2011 Hello, I'm new here and need some help. I'm a beginner with PHP Here's what I have.... The index page looks like this: <? include("header.php"); ?> <? include("sidebar.php"); ?> <? include("main.php"); ?> <? include("footer.php"); ?> On all of the pages for the site, the only thing that will change will be: <? include("main.php"); ?> When viewing the home page, the title in the browser shows: Home Page (which is what I want). However, when clicking on links in the nav bar, I want the title to reflect those page names. For example, the code above displays the home page, but then if you click on (for example) "Bio's" in the navigation bar, it will take you to the Bio's page, obviously. the link for that menu item is: bio.php. The bio.php page looks like this: <? include("header.php"); ?> <? include("sidebar.php"); ?> <div> All the data and formatting for this page </div> <? include("footer.php"); ?> ............. I would like to put some php code in the header that will automatically detect the title of each page, how can I do this? Should I put <? title=Bio's Page ?> (or whatever page) at the top of each page, then call to it somehow from the header? Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/228006-getting-the-page-title-for-pages/ Share on other sites More sharing options...
chrispos Posted February 17, 2011 Share Posted February 17, 2011 The way I would do this is use if and else and call it using title. if { bio.php $title = 'Bio ETC'; { else { $title = 'Home Page' } echo "$title"; I hope this is what you are looking for Quote Link to comment https://forums.phpfreaks.com/topic/228006-getting-the-page-title-for-pages/#findComment-1175787 Share on other sites More sharing options...
TCombs Posted February 17, 2011 Author Share Posted February 17, 2011 Chrispos, thanks for your response! How would I write this for multiple pages? In the header.php file, what would I put in the title tag? (if anything) And for each of the pages, is that where I would put the php code you gave me? Meaning, would I go to the bio.php and at the top enter: <? if {bio.php $title = 'Bio ETC'; { else { $title = 'Home Page' } echo "$title"; ?> Then for the news.php page, i would enter this at the top: <? if {news.php $title = 'Bio ETC'; { else { $title = 'Home Page' } echo "$title"; ?> Am I on the right track?..lol Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/228006-getting-the-page-title-for-pages/#findComment-1175808 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.