Forum Moderators: coopster

Message Too Old, No Replies

Reusable Page Elements

PHP Includes II

         

madcat

3:57 pm on Sep 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's goin' on-

I'd like to `include` page elements within my documents. They would be the standard header, navigation and footer elements.

But for the header, that would require my `title` and `meta` tags be set-up as variables for each new page.

So where exactly do I put the information to fill those variables. On the .html page or the includes page?

Is this the correct assumption? What are some other ways of going about this?

Thanks for any help!

Friday

4:15 pm on Sep 11, 2003 (gmt 0)

10+ Year Member



Here's how I do it...

At the top of each page I call my "header"...

#####################
<?require ("/full/path/to/top.html");?>
#####################

"top.html" looks something like this:

#####################
// call my "config" file
<?require_once("/full/path/to/template_config.html");?>

<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?echo("$Title\n");?>
<meta name="keywords" content="<?echo("$Keywords");?>">
<meta name="description" content="<?echo("$Description");?>">
#####################

"template_config.html" looks like this:

#####################
<?
if($PATH_TRANSLATED == "/full/path/to/page1.html"){
$Title="<TITLE>Welcome to Page 1</TITLE>";
$Description="This is page 1. It is a good page.";
$Keywords="keyword1,keyword2,keywortd3";
$header_text="<P ALIGN=\"CENTER\"><font face=\"Arial, Helvetica, sans-serif\" size=\"3\" color=\"#6363ef\"><B>Welcome to Page 1!</B></font></P>";
$header_jpg="http://www.yourdomain.com/images/page1_header.jpg";
}
else if($PATH_TRANSLATED == "/full/path/to/page2.html"){
$Title="<TITLE>Welcome to Page 2</TITLE>";
$Description="This is page 2. It is a good page.";
$Keywords="keyword1,keyword2,keywortd3";
$header_text="<P ALIGN=\"CENTER\"><font face=\"Arial, Helvetica, sans-serif\" size=\"3\" color=\"#6363ef\"><B>Welcome to Page 2!</B></font></P>";
$header_jpg="http://www.yourdomain.com/images/page2_header.jpg";
}
// etc., etc., etc....
?>
#####################
Hope that helps.
Friday

[edited by: Friday at 4:23 pm (utc) on Sep. 11, 2003]

Friday

4:22 pm on Sep 11, 2003 (gmt 0)

10+ Year Member



OBTW: Here's a little navigation element I put together from snippets I picked up somewhere along the way. (Sorry to the original authors) You could also call it from "top.html" wherever you want it:

<?include "/full/path/tol/navbar.html";?>

##############################
<?
$links_arr = array("Home" => "http://www.YourDomain.com/",
"Store Tour" => "http://www.YourDomain.com/departments.php4",
"Shop" => "http://www.YourDomain.com/cart/",
"Classes/Events" => "http://www.YourDomain.com/classes.php4",
"About Us" => "http://www.YourDomain.com/about_us.php4",
"Find Us" => "http://www.YourDomain.com/find_us.php4",
"Forums" => "http://www.YourDomain.com/sewing_circle.php4",
"Tips" => "http://www.YourDomain.com/sewing_tips.php4",
"Services" => "http://www.YourDomain.com/special_services.php4");
$separator = " <FONT SIZE=\"1\" FACE=\"Times New Roman, Times, Serif\">¦</FONT> ";
for (reset($links_arr); $name = key($links_arr); next($links_arr)){
$hyper = 1;
if(strstr($PATH_TRANSLATED,$links_arr[$name])) {
$hyper = 0;
}
if ($hyper) {
print "<FONT FACE=\"Arial, Helvetica, sans-serif\" SIZE=\"1\">
<A HREF=\"" . $links_arr[$name]."\">$name";
}
#print $name;
if ($hyper){
print "</A></FONT>";
}
if ($hyper == 0){
print "<FONT FACE=\"Arial, Helvetica, sans-serif\" SIZE=\"1\" color=\"#006b6b\"><B>$name</B></FONT>";
}

if(next($links_arr)){
print $separator;
prev($links_arr);
}
}
?>

daisho

5:23 pm on Sep 11, 2003 (gmt 0)

10+ Year Member



I do something similiar but I don't put all the titles and such in one file. ie.

header.php:
<!-- Start -->
<html>
<head>
<title><?=$html_title?></title>
</head>
<body>
<!-- End -->

footer.php:
<!-- Start -->
</body>
</html>
<!-- End -->

mynewpage.php
<!-- Start -->
<?
$html_title='this is the title of my page';
include 'header.php';
?>
This is my content
<?include 'footer.php'?>

Obviously my actual files are a little more complicated but you get the idea. That way you set the HTML element variables then include the header. So each file contains it's content and title,meta desc,keywords or whatever.

daisho.

Friday

5:35 pm on Sep 11, 2003 (gmt 0)

10+ Year Member



That's a good way to do it, daisho.
I only chose to use the separate configuration file to hold all the pages' <HEAD> elements because I'm usually also in charge of SEO for the site, so "tweaking" can be made quickly within the one file.
Cheers,
Friday
:)

madcat

5:53 pm on Sep 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was wondering why you used the config file ;)

Thanks for your help-

daisho

6:00 pm on Sep 11, 2003 (gmt 0)

10+ Year Member



Friday that makes total sence. In my case I do *EVERYTHING* since it's my site. I don't have to worry about other people messing up any SEO. If the jobs are seperate than a config files seems like a good tool to use.

daisho.

Friday

6:20 pm on Sep 11, 2003 (gmt 0)

10+ Year Member



I was wondering why you used the config file

And, if you're cloaking on a particular site or even a troublesome page (a page with white text on a Background image or a colored table cell that the client will NOT change, for example), then the config file makes sure that "page1.html" and "page2.html" have IDENTICAL <HEAD> content. If you get my drift.
;)
Friday