foucquet Posted August 25, 2010 Share Posted August 25, 2010 I am using a header as an include, now I am wondering if there is a simple way, using php, of giving each page a seperate title, instead of them all having the standard title in the header? Quote Link to comment https://forums.phpfreaks.com/topic/211698-page-titles/ Share on other sites More sharing options...
Alkimuz Posted August 25, 2010 Share Posted August 25, 2010 i guess that there is some kind of way that the pages are different from each other? you can use that difference to assign different names before the include and within the include refer to that with a variable for example, the pages are different by url and the urls are: website.com?page=1 and website.com?page=2 etc. you can ask that name and change it with: if ($_GET['page'] == '1') $title = 'The name of the first page'; if ($_GET['page'] == '2') $title = 'The name of the second page'; and within your include you place echo '<title>'.$title.'</title>'; something like this? Quote Link to comment https://forums.phpfreaks.com/topic/211698-page-titles/#findComment-1103569 Share on other sites More sharing options...
Adam Posted August 25, 2010 Share Posted August 25, 2010 Perhaps the simplest way would be to set a variable before the include: $page_title = 'Your title here'; require 'header.php'; Then check within the template file if the variable's been set: <title><?php if (!empty($page_title)) echo $page_title; else 'Default title here'; ?></title> Quote Link to comment https://forums.phpfreaks.com/topic/211698-page-titles/#findComment-1103571 Share on other sites More sharing options...
The Eagle Posted August 25, 2010 Share Posted August 25, 2010 <?php $title1 = "Title for Page 1"; $ip = $_SERVER['REMOTE_ADDR']; ?> <HTML> <HEAD> <TITLE><?php echo $title1; ?></TITLE> </HEAD> <BODY> <h1><?php echo $ip; ?> is your IP address....</h1> </BODY> </HTML> ... is what I briefly had in mind. Quote Link to comment https://forums.phpfreaks.com/topic/211698-page-titles/#findComment-1103607 Share on other sites More sharing options...
Adam Posted August 25, 2010 Share Posted August 25, 2010 <?php $title1 = "Title for Page 1"; $ip = $_SERVER['REMOTE_ADDR']; ?> <HTML> <HEAD> <TITLE><?php echo $title1; ?></TITLE> </HEAD> <BODY> <h1><?php echo $ip; ?> is your IP address....</h1> </BODY> </HTML> ... is what I briefly had in mind. Oookay... What's with the IP? Quote Link to comment https://forums.phpfreaks.com/topic/211698-page-titles/#findComment-1103608 Share on other sites More sharing options...
The Eagle Posted August 25, 2010 Share Posted August 25, 2010 Oookay... What's with the IP? I thought it looked empty so I put a little bit more idea into it, just an example. Quote Link to comment https://forums.phpfreaks.com/topic/211698-page-titles/#findComment-1103612 Share on other sites More sharing options...
foucquet Posted August 25, 2010 Author Share Posted August 25, 2010 O K, thanks folks. I can see that I am going to have an evening of experimentation Quote Link to comment https://forums.phpfreaks.com/topic/211698-page-titles/#findComment-1103629 Share on other sites More sharing options...
foucquet Posted August 25, 2010 Author Share Posted August 25, 2010 Perhaps the simplest way would be to set a variable before the include: $page_title = 'Your title here'; require 'header.php'; Then check within the template file if the variable's been set: <title><?php if (!empty($page_title)) echo $page_title; else 'Default title here'; ?></title> OK so a couple of experiments tell me this is not only the easiest, but also the simplest solution, and works perfectly - well it did after I got over the problem of putting a single quote in the title Thanks MrAdam Quote Link to comment https://forums.phpfreaks.com/topic/211698-page-titles/#findComment-1103640 Share on other sites More sharing options...
Adam Posted August 26, 2010 Share Posted August 26, 2010 No problem Quote Link to comment https://forums.phpfreaks.com/topic/211698-page-titles/#findComment-1103869 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.