Jump to content

Calling Footer from Single File to Several Files


amitamberker

Recommended Posts

Hello Everyone, How do I call "Footer" from Single File to Several Files? footer.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ransitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Footer</title><style type="text/css">body { margin-top: 0px; text-align: center;}.footer { width: 800px; height: 30px; text-align: center; font-family: verdana; font-size: 8pt; line-height: 30px; background-color: #CACACA;}</style></head><body><div class="footer">blah... blah... blah... © 2003 - 2012. | All rights reserved</div></body></html>
SeveralPages.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ransitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>SeveralPages</title><style type="text/css">body { margin-top: 0px; text-align: center;}#Container { width: 800px;}.Header { height: 80px; background-color: Red;}.Body { height: 200px; background-color: Green;}</style></head><body><div id="Container"><div class="Header">...</div><div class="Body">...</div><div style="height:30px;line-height:30px">So, how do I call "footer.html" page here?</div></div></body></html>
Edited by creative1977
Link to comment
Share on other sites

First, your file to include should not be a complete HTML document, it should only contain the code that you want to insert in your other files. You can use PHP's include or require statements to include the code from the other file wherever you want it to in your main file. http://www.w3schools.com/php/php_includes.asp

Link to comment
Share on other sites

First, your file to include should not be a complete HTML document, it should only contain the code that you want to insert in your other files. You can use PHP's include or require statements to include the code from the other file wherever you want it to in your main file. http://www.w3schools...hp_includes.asp
Hi justsomeguy,Hope all is well at your end. Thanks for your response.As you are aware, I don't know PHP. I mean, I cannot design Footer Concept in ".php" based file.I am not sure how to add the following into a .php file:
<style type="text/css">body {margin-top: 0px;text-align: center;}.footer {width: 800px;height: 30px;text-align: center;font-family: verdana;font-size: 8pt;line-height: 30px;background-color: #CACACA;}< /style>< /head>< body>< div class="footer">blah... blah... blah... © 2003 - 2012. | All rights reserved</div>
Link to comment
Share on other sites

Look at the link to the tutorial. You don't need any PHP code in the file to include, you're just using PHP's include mechanism to include the code, which is a single PHP statement in the parent file. You also don't want extra </head> or <body> tags in the code to include. All of the CSS information should also probably be in the parent page in the head section where it belongs, or in an external CSS file.

Link to comment
Share on other sites

Look at the link to the tutorial. You don't need any PHP code in the file to include, you're just using PHP's include mechanism to include the code, which is a single PHP statement in the parent file. You also don't want extra </head> or <body> tags in the code to include. All of the CSS information should also probably be in the parent page in the head section where it belongs, or in an external CSS file.
Hi justsomeguy, Okie, let me try that... Thanks! Edited by creative1977
Link to comment
Share on other sites

Hi justsomeguy, Alrighty, here I go: footer.php

<div>blah... blah... blah... © 2003 - 2012. | All rights reserved</div>
SeveralPages.html
<style type="text/css">body { margin-top: 0px; text-align: center;}#Container { width: 800px;}.Header { height: 80px; background-color: Red;}.Body { height: 200px; background-color: Green;}.footer { width: 800px; height: 30px; text-align: center; font-family: verdana; font-size: 8pt; line-height: 30px; background-color: #CACACA; }</style></head><body><div id="Container"><div class="Header">...</div><div class="Body">...</div><div class="footer"><?php include 'footer.php'; ?></div></div>
1. Somehow "blah... blah... blah... © 2003 - 2012. | All rights reserved" is not visible?2. Upon publishing on IE Web Browser, the whole Container (Design) is moving towards Left Side? Edited by creative1977
Link to comment
Share on other sites

Make sure you're accessing the files via HTTP, PHP will not run if you're not accessing the files through a web server. You can't just double-click on a file and have PHP code get executed. If that "severalpages.html" is your complete code, you're missing the doctype and opening tags. You also need to rename that to a .html file, your server is probably not configured to use PHP to process .html files, only .php files. Your include file can be a .html file, because there's no PHP code in it, but for the sake of future maintainability it's probably best to use all .php files.

Link to comment
Share on other sites

Make sure you're accessing the files via HTTP, PHP will not run if you're not accessing the files through a web server. You can't just double-click on a file and have PHP code get executed. If that "severalpages.html" is your complete code, you're missing the doctype and opening tags. You also need to rename that to a .html file, your server is probably not configured to use PHP to process .html files, only .php files. Your include file can be a .html file, because there's no PHP code in it, but for the sake of future maintainability it's probably best to use all .php files.
Hi justsomeguy, Feeling very hard to understand what you are saying. But please find the attached "footer.php" and "SeveralPages.html" files. Please let me know where am I going wrong and what should I do.So, how should I make sure I am accessing the files via HTTP?
Link to comment
Share on other sites

The code looks fine. When you are looking at your page in the browser the URL needs to start with HTTP, not "file://" or anything else. You need to have your page on a web server that supports PHP and navigate to that URL like you would to any other page.

Link to comment
Share on other sites

The code looks fine. When you are looking at your page in the browser the URL needs to start with HTTP, not "file://" or anything else. You need to have your page on a web server that supports PHP and navigate to that URL like you would to any other page.
Hi justsomeguy, Thank you for saying that code looks fine (I am glad to know about it). So, you mean: Instead of this:
E:\Calling-Footer-Into-Several-Files\SeveralPages.html
It should be like this?
By the way I have Uploaded into my Domain which supports PHP but still it's not displaying properly? Edited by creative1977
Link to comment
Share on other sites

You have it backwards. the page that is doing the include (i.e. the several pages) must be a PHP page (it can still contain a mix of PHP/HTML, but it should end with .php. The footer can just be the HTML snippet you want to include. Since you said you don't know PHP, it would make sense that you familiarize yourself with some of the basics.http://www.w3schools...php/default.asp

Edited by thescientist
Link to comment
Share on other sites

The code looks fine. When you are looking at your page in the browser the URL needs to start with HTTP, not "file://" or anything else. You need to have your page on a web server that supports PHP and navigate to that URL like you would to any other page.
Hi justsomeguy, Thank you for saying that code looks fine (I am glad to know about it). So, you mean: Instead of this:
E:\Calling-Footer-Into-Several-Files\SeveralPages.html
It should be like this?
By the way I have Uploaded into my Domain which supports PHP but still it's not displaying properly? Hi thescientist, Please WAIT. Please don't reply. Please do not confuse me. I am waiting for justsomeguy's reply. (no, I am not being rude with you.) Edited by creative1977
Link to comment
Share on other sites

You need to use .php for any files that you want to run PHP code in.
Hi justsomeguy, Welcome Back! So you mean, I should Re-Name "SeveralPages.html" as "SeveralPages.php" ? Edited by creative1977
Link to comment
Share on other sites

Yes.
Hi justsomeguy, But you NEVER EVER told me that during our Back and Forth Discussion?... Well - NO WAY. I do not want to ReName all those pages from .html to .php I want to Call Footer Segment from a Single File to Several HTML Web Pages. As per your recommendation I made the Footer File as .php ... So, how do I get that into HTML file? Edited by creative1977
Link to comment
Share on other sites

I tried to tell you that in post 7. thescientist also told you that.

Well - NO WAY. I do not want to ReName all those pages from .html to .php
That's fine, that means that you either need to configure your server to use PHP for .html files, or not use PHP. Whatever you want to do.
I want to Call Footer Segment from a Single File to Several HTML Web Pages. As per your recommendation I made the Footer File as .php ... So, how do I get that into HTML file?
I told you to make the file that is doing the including, not the file to be included, a .php file. I actually suggested making both of them .php files so that you don't need to change filenames again later. If you want to run PHP code, then you need to use a .php file, that's the bottom line. You can't run PHP code in a .html file if your server is not configured to use PHP for .html requests.
Link to comment
Share on other sites

like I said earlier....

Since you said you don't know PHP, it would make sense that you familiarize yourself with some of the basics.http://www.w3schools...php/default.asp
one of the first thing it covers is file naming conventions, how to run and view pages, and there are tutorials on using include.
Link to comment
Share on other sites

Guest So Called

HTML does not have any include function. I wonder if the OP could add a JavaScript that uses JS techniques to write the common footer at the end of his document. Maybe that would make him happy. I think when I first learned PHP (and had been using flat HTML files for my site before that) one of the biggest initial benefits was that I could have a common header and common footer included, and not have to edit every content page on my site every time I wanted to change the header/footer. It's much the same as beginning to use CSS, where you can change the appearance of all your content pages by editing only one file (your CSS script). Edit: It's interesting to note that this topic was posted in the JavaScript section of the forum. I'm surprised nobody has made the suggestion I made above instead of bringing up PHP include files. I'm pretty sure JS could add his common footer but I'm no JS expert and I don't want to bother to try to write some working code when the JS experts could probably do it off the top of their head.

Edited by So Called
  • Like 1
Link to comment
Share on other sites

You can use an ajax request to load external content but that's going to cause a delay and some jumping during the page load and may reduce functionality in terms of event handlers that you want to have in the included content. There is no delay with a PHP include, the content is all sent to the browser as a single response, and since it's one response there's no loss of other Javascript functionality.

Link to comment
Share on other sites

Hi justsomeguy, CodeName, thescientist, and So CalledI am totally and absolutely confused. JUST DON'T KNOW what to do now. I am literally blind now. Just not able to decide how to resolve this concern :(Could someone PLEASE provide me an EASY and SIMPLE solution? I thought dsonesuk would pop-up here but he hasn't........... Maybe I think dsonesuk doesn't want to help me anymore.

Link to comment
Share on other sites

what is making you confused? it is as simple as everyone told you. you need to rename the calling file to .php. did you make that?

Link to comment
Share on other sites

what is making you confused? it is as simple as everyone told you. you need to rename the calling file to .php. did you make that?
I have already made it. It's "footer.php" ... But I do not want to ReName "SeveralPages.html" file as "SeveralPages.php". Because, there are around 40 HTML Pages. I do not want to make those 40 HTML pages as .php Edited by creative1977
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...