Forum Moderators: open
Each of my web pages on my site (about 20 ish), has a "header, footer, and side menu" as a php include. For example, my index.php has a header.html, footer.html, and menu.html include.
I'm wondering what would be the proper way to code in the following:
1. Where do I put my link to my style sheets? I.E// in the header file / in every page of my site (i.e// page1.html, page2.html, etc)? Or both?
2. For the includes (i.e.// for the header / footer /menu), should they include a title / head tags? (i.e.// <head><title>?)
3. Where do i put my title tags so that each page is named appropriately? I'm assuming this would be on each page.html file?
4. Is this a good way to go about doing this?
Any input appreciated.
Andrew.
1. Where do I put my link to my style sheets? I.E// in the header file / in every page of my site (i.e// page1.html, page2.html, etc)? Or both?
2. For the includes (i.e.// for the header / footer /menu), should they include a title / head tags? (i.e.// <head><title>?)
3. Where do i put my title tags so that each page is named appropriately? I'm assuming this would be on each page.html file?
In page.html
<?php
$page_title="The title of the page";
include 'header.php';
?>
Page content
<html>
<head>
<title><?php echo $page_title;?></title>
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
</head>
<body>
....
Post back if you need more help,
Elijah
Should my footer.html and menu.html file contain and header/title tags at all?
No, You wouldn't need head/title tags in those pages. As Elijah stated, you can use the echo function and define the title as a variable to get it included in the page.
Whatever you include in header.php would be conveyed to all the includes, page content etc.
Sid
PHP includes aren't like documents that go inside frames - they can be anything, from a single unit like a counter number, or a page full of HTML text. So there's no need to add anything extra to the files to 'validate' them.
Remember, they can be any type of document too - eg: "footer.html", "footer.txt" or "footer.php", depending on what's in the included file. Note the last one - you can include more PHP in the file and it will be acted on when the file is included. This can be useful sometimes.
I've seen a lot of threads on here about this, perhaps too many, because I'm now confused more than before. I want to use php includes, but I'd like to keep the .html extenstions. I think the proper terminology is parsing php as html, correct? And I have to add something to the .htaccess file, right? What exactly would that be?
Jennifer
Works great.
Sticky me if you need any help - I can provide you the exact code.
Sid
I'll call this file my_widget_page.php
<?
include( 'includes/page_setup.php' );
include( 'includes/content/widget/setup.php' );
include( 'includes/page_header.php' );
include( 'includes/content/widget/page.php' );
include( 'includes/page_footer.php' );
?> Now I create a folder called includes in the same directory. I apply security to the folder by denying access to outside visitors. This stops anyone from viewing the files that will be inside the includes folder.
I then create a file inside of the includes folder called page_setup.php
Next I create a folder called widget and inside that folder a file called setup.php.
And finally I create the last three files, page_header.php, widget/page.php, and page_footer.php.
The final step is making my files easy to remember on the web by using .htaccess.
RewriteEngine on
RewriteRule ^widget$ /my_widget_page.php [L] Now my page address looks like this http://example.com/widget
The great thing about using this method is that I could switch to asp, lets say, and my visitors would never know the difference. I would just change my .htaccess file to look like this,
RewriteEngine on
RewriteRule ^widget$ /my_widget_page.asp [L] The url is still http://example.com/widget
Good luck :)
I have more question, is it possible to do something simliar with Meta Tags? I.E//, put the meta tags in the "page1 / page2.html file", and then have it so that the "header" calls the meta tag from the file? (does that make sense)
i.e// in page.html, you have
<?php
$page_title="The title of the page";
include 'header.php'; $page_meta="whatever keywords";
?>
And then in the header have:
<html>
<head>
<title><?php echo $page_title;?></title>
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
<meta $page_meta>
</head>
Anyways, is this possible? does that make sense?
<?php
$page_title="The title of the page";
include 'header.php'; $page_meta="whatever keywords";
?>And then in the header have:
<html>
<head>
<title><?php echo $page_title;?></title>
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
<meta $page_meta>
</head>
The parser reads the script the same way you read a book. Left to right and top to bottom.
Anything you define before the include statement will be availabe in the included file.
Since your $page_meta variable is defined after your include it wont be available in your included file.
This will work,
$page_title="The title of the page";
$page_meta="whatever keywords";
include 'header.php';<?
echo'
<title>'. $page_title .'</title>
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
<meta name="Keywords" content="'. $page_meta .'" />
</head>
';
?>
And finally I create the last three files, page_header.php, widget/page.php, and page_footer.php.# These three files are just plain html that is echoed by php. I just plug in the variables I created in the setup pages.
Shouldn't these files have ".html" extensions? Otherwise each is calling the PHP parser for no reason.
These three files are just plain html that is echoed by php
I meant that these pages are the structure of my page. I don't define variables are add coding to setup the page on this page. This is the page where I echo my html tags to the browser.
I just plug in the variables I created
Something like this,
<?
// Page header.php
echo'
<html>
<title>'. $page_title .'</title>
<meta description="'. $page_description .'" />
<body><h1>'. $page_heading .'</h1>
';
?>
Turning the whole page into php allows me to add comments to the code that won't be sent to the users browser and I personally think it's easier to edit the page without having <? echo $var1;?>some html code<? echo $var2;?> all throughout the page.
I am not a expert or anything but I don't understand why people that use php don't just make all their pages pure php. It looks cleaner and is much easier to edit in my opinion. (but this is the opinion of someone who is up at four in the morning)
RewriteEngine on
RewriteRule ^widget$ /my_widget_page.php [L]
RewriteRule ^widget.html$ /my_widget_page.php [L]
RewriteRule ^widget.htm$ /my_widget_page.php [L]
RewriteRule ^widget.php$ /my_widget_page.php [L]
RewriteRule ^widget.asp$ /my_widget_page.php [L]
Now a person could type in and of the following and would still get my_widget_page.php
http://example.com/widget
http://example.com/widget.html
http://example.com/widget.htm
http://example.com/widget.php
http://example.com/widget.asp
and in case your wondering, if you want to make your homepage my_home_page.php open when a person types in http://example.com then,
RewriteRule ^$ /my_home_page.php [L]
There are other ways to accomplish this, try the Apache Web Server [webmasterworld.com] forum here at webmasterworld.
My header header.html file looks like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE><?php echo $page_title;?></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META NAME="Author" CONTENT="WEBSITE">
<META NAME="Keywords" CONTENT="PENDING KEYWORDS">
<LINK REL=STYLESHEET TYPE="text/css" HREF="style/style.css">
</HEAD>
And my page.html file looks like this:
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=754>
<TR VALIGN=TOP ALIGN=LEFT>
<TD HEIGHT=218 WIDTH=754><?php $page_title="The title of the page"; include("header.html");?>
</TD>
</TR>
</TABLE>
BUT..when i do a view source of the page in a webbrowser (with the include and all) it messed up the code and looks likes this:
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=754>
<TR VALIGN=TOP ALIGN=LEFT>
<TD HEIGHT=218 WIDTH=754><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>The title of the page</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META NAME="Author" CONTENT="WEBSITE">
<META NAME="Keywords" CONTENT="PENDING KEYWORDS">
<LINK REL=STYLESHEET TYPE="text/css" HREF="style/style.css">
</HEAD>
ANy ideas why?
<?php $page_title="The title of the page"; include("header.html");?>
<body>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=754>
<TR VALIGN=TOP ALIGN=LEFT>
<TD HEIGHT=218 WIDTH=754>site content</TD>
</TR>
</TABLE>
</body>
</html> And of course, don't forget the body tag. :)
Jennifer