• 0

Including certain file in each webpage


Question

This might be something really easy, but im just not having any success at all. Basically right now, i have been asked by a friend to create a basic information website which will have just text and some images. I have made a css drop down menu which I want to include automatically on every single webpage rather than copy and pasting the code one ach individual page. How can I do this? Does it have to be a php file or can it be html? And also will this only work once its uploaded on a hosting site? or can it work just as a local file on a pc which I double click.

Right now when I create a test page and then do the include tag the page is still blank and does not bring up the menu.html file.

I hope this isnt confusing.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

You'll need to use a language like PHP to include it on the page. I believe you can do it with HTML5 too using the object tag but you'll lose compatibility among older browsers

You'll also need to have support for that language on your server, also if you're building locally, you'll need to setup a local server for testing.

In PHP it is simple

 <?php include_once('filename'); ?>

Link to comment
Share on other sites

  • 0

As they said above, you will need to have something similar to WAMP installed if you're running Windows. Then you will be able to do local PHP development. After you get it together though, it shouldn't be too difficult. Here is how your standard file would be layed out:


<?php
include_once('header.php');
?>
<div id="content">
</div>
<?php
include_once('footer.php');
?>
[/CODE]

'header.php' includes the Doctype, opening html tag, complete head tags, and usually all the code within the body tag that holds your site logo and navigation (usually), and 'footer.php' holds all the code for your site's footer along with the closing body tag and html tag. Having the '.php' extension instead of '.html' will not affect any of your files unless they have PHP code in them. It just informs your server to parse through the code before outputing the document to the client.

Hopefully that clears some things up!

Link to comment
Share on other sites

  • 0

what would be the best product to use to test it locally?

sorry just realized you mentioned wamp. Will try it out, what about the standard iis one that comes with windows is that any good? Not sure if its even included win7 anymore.

Link to comment
Share on other sites

  • 0

Windows never included a server with their desktop OSes afaik. You can probably use the Windows one if you're on Win Server.

But check out Server Side Includes if you're not doing any actual scripting, it's simpler than making barebones PHP files just for the purpose of using an include function.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.