nubby Posted August 20, 2008 Share Posted August 20, 2008 So, I know xhtml/css/javascript pretty well and I just started learning php recently. I am going through all my current sites and fixing things so my code looks a lot better and I get better coding techniques. But I was wondering what is the best way to include title element on all pages without having to individually change each page? Would I just start the title string on the index page and call for $title string on all my other pages so when I want to edit it I only have to do that on the index page? Same with keywords and description? Can someone explain how I would do this a little better? Sorry I am really really new to php. Link to comment https://forums.phpfreaks.com/topic/120606-best-technique-for-the-head-element/ Share on other sites More sharing options...
GreenUser Posted August 20, 2008 Share Posted August 20, 2008 What's up? I have something like this in my config files. Then have that file required before the html code. <?php $sitename = "My Web Site"; ?> Then for the title ... <title><?php echo $sitename; ?></title> I keep the html header stuff in another file called header, which I require on every page. Hope it helps. Link to comment https://forums.phpfreaks.com/topic/120606-best-technique-for-the-head-element/#findComment-621486 Share on other sites More sharing options...
nubby Posted August 20, 2008 Author Share Posted August 20, 2008 What's up? I have something like this in my config files. Then have that file required before the html code. <?php $sitename = "My Web Site"; ?> Then for the title ... <title><?php echo $sitename; ?></title> I keep the html header stuff in another file called header, which I require on every page. Hope it helps. So for all your sites you have meta and head element information like title, keywords, description in a file called config.php? And then basically in the header do: <title><?php echo $sitename; ?></title> But then what do you do for keywords and all that? Sorry if I sound like the biggest beginner. :-X Link to comment https://forums.phpfreaks.com/topic/120606-best-technique-for-the-head-element/#findComment-621493 Share on other sites More sharing options...
GreenUser Posted August 20, 2008 Share Posted August 20, 2008 You could do the same ... <meta name="<?php echo $config_keyword; ?>" content="<?php echo $config_description; ?>"> I would just use something like this, make a header file, then use it in in all of your files. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head> <meta name="Milk" content="Moo, Moo, Moo!"> <title>Milk Jugs</title> <link href="ss.css" rel="stylesheet" type="text/css" /> <body> <div id="main"> Using variables is nice too, but if you have it all in one file, like config.php or header.php it is easier to modify. <?php require('header.php'); ... content goes here ... ?> Link to comment https://forums.phpfreaks.com/topic/120606-best-technique-for-the-head-element/#findComment-621497 Share on other sites More sharing options...
DeanWhitehouse Posted August 20, 2008 Share Posted August 20, 2008 going on that i would recomend this header.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head> <meta name="<?php echo $meta_name;?>" content="<?php echo $content;?>"> <title><?php echo $title;?></title> <link href="ss.css" rel="stylesheet" type="text/css" /> <body> then index.php <?php $meta_name = "Meta Name"; $content= "content"; $title = "Page title"; require_once 'header.php'; ?> Link to comment https://forums.phpfreaks.com/topic/120606-best-technique-for-the-head-element/#findComment-621500 Share on other sites More sharing options...
nubby Posted August 21, 2008 Author Share Posted August 21, 2008 Thanks a lot guys this should help me a lot more. This seems a lot easier than going back and editing 20+ files. But I did those when I was first learning xhtml and trying to get better web design techniques and style. Link to comment https://forums.phpfreaks.com/topic/120606-best-technique-for-the-head-element/#findComment-621787 Share on other sites More sharing options...
Lamez Posted August 21, 2008 Share Posted August 21, 2008 here is what I have: $path = "../../"; $title = "Marked Paid"; $rank = "yes"; include ($path."main/include/cons/head.php"); that is on every page Link to comment https://forums.phpfreaks.com/topic/120606-best-technique-for-the-head-element/#findComment-621791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.