homepage Welcome to WebmasterWorld Guest from 54.196.77.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Include header.php
different titles on each page
bugsy2334




msg:1293766
 10:39 pm on Apr 6, 2003 (gmt 0)

I'm kind of new to php, so this might me a real simple question. I want to have a different title on every page. The way my pages are set up right now is to include my header.php file.

In my title on my header.php file i have something that looks like this <title>abc 123 <? echo $title;?></title>.

On all my other pages, on the top of each page, i have <? $title = ''; include "header.php";?>.

The way my site works now is that every page i go to has the same title and meta tags. I would like to change it so i can have different title on each page.

Im sure this is pretty simple to do, I just don't know how to do it.

Thanks
Bob

 

andreasfriedrich




msg:1293767
 11:03 pm on Apr 6, 2003 (gmt 0)

Instead of setting $title to the empty string set it to an individual title before you include [php.net] header.PHP [php.net]. The included file will inherit the scope of the line calling include [php.net]. Thus $title will be different for each page.

Andreas

bugsy2334




msg:1293768
 11:57 pm on Apr 6, 2003 (gmt 0)

I knew it would be simple. Thanks for the reply.

willybfriendly




msg:1293769
 4:25 am on Apr 7, 2003 (gmt 0)

Call it as a function, i.e.:

<?
function do_html_header($title)
{
//formats a nice header
?>
<html>
<head>
<title><? $title?></title></TITLE>
</head>
<BODY>
<H1>Your site name</H1>
<HR>
//custom heading will be printed here via do_heading call
<?
if($title)
do_html_heading($title);
}

function do_html_footer()
{
// print an HTML footer
?>
</body>
</html>
<?
}

function do_heading($heading)
{
// print heading
?>
<h3><?=$heading?></h3>
<?
}

You can include all 3 of these functions in one include or require statement. Coding your pages becomes simplicity itself.

<?
require_once("html_fns.php");

do_html_header("Using Includes for Page Layout");

?>

<P> Your content here </P>

<?
do_html_footer()
?>

Hope this is of some help.

WBF

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved