Using include files

Discuss all aspects of programming here.

Moderator: The Mod Squad

Using include files

Postby Toby B. » Mon Nov 22, 2004 11:24 pm

Ok I have a little knowlege of this project. But I am a tad bit cofused on exactly what to use in the header include file.
Code: Select all
<HEAD>


<TITLE>Consumer Technical Information - Index</TITLE>

<meta NAME="description" CONTENT="Your number one resource for Compaq and HP information.">
   <meta NAME="keywords" CONTENT="Compaq, Compaq PC's, compaq computers, Compaq technical support, computer hardware, compaq information, Compaq motherboards, Aspen, Aspen2, BMW/BMW-2, BMW-R, CAMARO, CE-31A, KBI-6130, KBA-6130, Mitac, FIC, Trigem, Asus, UIB1, ZZ-Top, MSI, MS-6553, Intel, BI440ZX, TR100, LORRETTO, Uwave, Uwave2, Uwave3, Uwave-R, AZ31, Pipeline, ELISE/ELISE-SWAP, Compaq Maintanence/Sevice Guides, motherboards, mainboards, mobos">
   <meta NAME="author" CONTENT="Toby Bibeau">
   <meta NAME="robots" CONTENT="All">

<link rel="stylesheet" href="./common/compaq_style.css" type="text/css">


</HEAD>


If I use the whole bit in the header.inc file each page will get the same title. So the question is can I leave the top piece (i.e. the open HEAD and TITLE tags) out of the header.inc file and that way I can have a univesal look to the pages and still have individual titles?

Another thing that I need to work on is my keywords for the META tags. Seems I have too many and the are not concise enough...

any thoughts?
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby MoboCop » Tue Nov 23, 2004 5:50 pm

ah one of my favorite subjects.

using includes is an excellent way of using two files to handle the look of your site.

Allows you to maintain your page in two files. A header and footer.

The simplest way to do this is to pass variables to the included files.

So your meta tag title in the header file you posted would be handled as follows.

In the calling page you would set a variable in php.

$meta_title = "My Page";

then you would call the included page

include('mypage.php');

The mypage.php would contain mostly straight html code except where you want variable values to go.

<head>
<title><?php echo $meta_title; ?></title>

Now you can do this method for any values that might vary from page to page. Very simple yet extremely powerful.

Using a header and footer like this allows you to maintain your site code in two files.

Motherboards.org using this basic concept, although I wrap the includes insides functions in a class which gives me more flexibility than straight includes.

As for key words, based on research done in June I no longer use keywords at all. Google does not use them at all anymore in their ranking.

Hope this helped.
Not everything that can be counted counts, and not everything that counts can be counted - Albert Einstien
MoboCop
Drunken Master
 
Posts: 8854
Joined: Tue Jan 18, 2000 1:01 am
Location: Fresno

Postby Toby B. » Tue Nov 23, 2004 8:24 pm

Thanks a bunch. I will look into this more next week..
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby Toby B. » Mon Dec 13, 2004 6:26 am

Patrick, I am just now taking another crack at the includes project that I had posted in the forum a couple of weeks ago...

I am a bit confused on what should go where and how to get the header to show the proper title for each page.

Proposed header file:
Code: Select all
<DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www/w3c/org/TR/html4/strict.dtd">
<HTML>
<head>
<title><?php echo $meta_title; ?></title>

<meta NAME="description" CONTENT="Your number one resource for Compaq and HP information.">
   <meta NAME="keywords" CONTENT="Compaq, Compaq PC's, compaq computers, Compaq technical support, computer hardware, compaq information, Compaq motherboards, Aspen, Aspen2, BMW/BMW-2, BMW-R, CAMARO, CE-31A, KBI-6130, KBA-6130, Mitac, FIC, Trigem, Asus, UIB1, ZZ-Top, MSI, MS-6553, Intel, BI440ZX, TR100, LORRETTO, Uwave, Uwave2, Uwave3, Uwave-R, AZ31, Pipeline, ELISE/ELISE-SWAP, Compaq Maintanence/Sevice Guides, motherboards, mainboards, mobos">
   <meta NAME="author" CONTENT="Toby Bibeau">
   <meta NAME="robots" CONTENT="All">

<link rel="stylesheet" href="./common/compaq_style.css" type="text/css">


</HEAD>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" width="fixed">
<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr width="50%" bgcolor="#8b0000">
<td><p><b><font color="#FFFFFF">&nbsp;-Your #1 Source For Compaq & HP Info-</font></b></p></td>
<td width="50%" bgcolor="#8b0000">
          <p align="right"><font color="#FFFFFF">&nbsp;
           <SCRIPT LANGUAGE="Javascript">
           <!--
           var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
           var months = new Array("January","February","March","April","May","June","July","August",
           "September","October","November","December");
           var now = new Date();
         var year = now.getYear();
         if(year<1000)
         year+=2000;
           document.write(days[now.getDay()] + ", " + months[now.getMonth()] + " " + now.getDate() + ", " + year);
           // -->
           </SCRIPT>&nbsp;</p>
           </FONT></td>
</tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="white">
<tr>
<td width="100%" valign="top" bgcolor="#C0C0C0">
          <p align="center"><font color="#000000">Advertisement</font><br/>
          <script type="text/javascript"><!--
google_ad_client = "pub-6710097386419537";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="";
google_ad_type = "text_image";
google_color_border = "336699";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p></td>

</tr>
</table>

<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr width="100%" bgcolor="#8b0000">
<td>&nbsp;<a href="index.html" class="sidenav">Home</a> <font color="#ffffff">|</font> <a href="quickspecs/index.html" class="sidenav">Quickspecs</a> <font color="#FFFFFF">|</font> <a href="./smatrix/index.html" class="sidenav">Serial Matrix</a> <font color="#FFFFFF">|</font> <a href="contact.html" class="sidenav">Contact Us</a> <font color="#FFFFFF">|</font> <a href="./forum/index.php" class="sidenav">Forum</a> <font color="#FFFFFF">|</font> <a href="./support.html" class="sidenav">Support and Drivers</td>

<td>
<div align="right"><table style="border: 0px solid black; background color: #8b0000; float: center;"><tr><td>
<center>&nbsp;</td></tr></table>
</div></td>
</tr>
</table>


If I make the above code into header.inc how would I add the header.inc file so that is showed the info?
page.html
Code: Select all
<?php
include (header.inc)
$meta_title = "My Page";
?>
<body>
.....
.....
<?php
include (footer.inc)
>


Did I lose you yet??

thanks in advance
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby MoboCop » Mon Dec 13, 2004 8:53 am

you have to set your title before you call the header file.

So

$meta_title = "blah blah";

then call the include

include('header.inc');

the header file has to be in your php include path.

So any variables you want to use in your header file you need to set before you call the header file. Basically the header file will be in scope where it is called on your page.
Not everything that can be counted counts, and not everything that counts can be counted - Albert Einstien
MoboCop
Drunken Master
 
Posts: 8854
Joined: Tue Jan 18, 2000 1:01 am
Location: Fresno

Postby Toby B. » Mon Dec 13, 2004 2:15 pm

hmm, still a bit fuzzy. But I will take another crack at it and see if I can figure it out..
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby MoboCop » Mon Dec 13, 2004 3:09 pm

Code: Select all
<?php
$meta_title = "My Page";
include (header.inc)

?>
<body>
.....
.....
<?php
include (footer.inc)
>


I copied your code from above. Notice I moved the $meta_title to come before the include statement. IF you call the include first the variable $meta_title does not exist yet (scope) therefore the include file cannot know what the value of $meta_title is. So with a quick line switch your page should work. the variable is set before the include is called and therefore the variable $meta_title will be available (in scope) for the code in the include file. Hope this makes more sense.
Not everything that can be counted counts, and not everything that counts can be counted - Albert Einstien
MoboCop
Drunken Master
 
Posts: 8854
Joined: Tue Jan 18, 2000 1:01 am
Location: Fresno

Postby Toby B. » Mon Dec 13, 2004 11:56 pm

Well the way you clarified it, I though I had it licked but for some reason things are not working properly.... :cry:

http://www.s87841630.onlinehome.us

The header does not show and the title is not working.. :?
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Postby MoboCop » Tue Dec 14, 2004 8:18 am

Toby B. wrote:Well the way you clarified it, I though I had it licked but for some reason things are not working properly.... :cry:

http://www.s87841630.onlinehome.us

The header does not show and the title is not working.. :?


ok first it looks like from your source that php is not being parsed. what extension are you using on your index file?

Second you need to have quotes around the file in your include statements.

include('path/file');

can be double or single quotes. Double quotes are parsed for variables, single are not.
Not everything that can be counted counts, and not everything that counts can be counted - Albert Einstien
MoboCop
Drunken Master
 
Posts: 8854
Joined: Tue Jan 18, 2000 1:01 am
Location: Fresno

Postby Toby B. » Tue Dec 14, 2004 8:54 am

The extension is .html
Toby B.
Lead Mobo-fu Master
Lead Mobo-fu Master
 
Posts: 14277
Joined: Sun Dec 16, 2001 1:01 am
Location: Maine

Next

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron