anteater Posted March 18, 2010 Share Posted March 18, 2010 Hello, I am not very good at PHP. I have a header and footer include in every page. Now I want a different title for each page. The code I inserted doesn't work. Can anyone help me? Thanks in advance. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/195658-page_title/ Share on other sites More sharing options...
PravinS Posted March 18, 2010 Share Posted March 18, 2010 According to your coding there is only way to pass PAGE_TITLE variable in page_header() function. Link to comment https://forums.phpfreaks.com/topic/195658-page_title/#findComment-1028002 Share on other sites More sharing options...
slurpee Posted March 18, 2010 Share Posted March 18, 2010 Although what you have done is not a good way to create your page header, this should work: On the first line after your "function page_header( $pict='top1.png' ) {" function declaration, add the following: global $page_title; Note: This is just a hack for your code to make the page title work; as I said it's not really good coding practice. If you want a more thorough explanation and/or example let me know. Link to comment https://forums.phpfreaks.com/topic/195658-page_title/#findComment-1028004 Share on other sites More sharing options...
anteater Posted March 18, 2010 Author Share Posted March 18, 2010 What is a better way to do this then? Link to comment https://forums.phpfreaks.com/topic/195658-page_title/#findComment-1028010 Share on other sites More sharing options...
slurpee Posted March 19, 2010 Share Posted March 19, 2010 I usually don't like outputting my template headers from a function, maybe it's just a preference but I find it pretty messy. What I'll do instead, is something like this: in index.php: <? $page_title = "AntEater B.V."; include "header.php"; ?> All my other body text <? include "footer.php"; ?> Then, in header.php you would have something like: <? $page_title = $page_title ? $page_title : 'Default Page Title'; ?> <html> <head> <title><?= $page_title ?></title> .... Link to comment https://forums.phpfreaks.com/topic/195658-page_title/#findComment-1028490 Share on other sites More sharing options...
anteater Posted March 30, 2010 Author Share Posted March 30, 2010 Thank you, I'll try this on! Link to comment https://forums.phpfreaks.com/topic/195658-page_title/#findComment-1033984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.