Welcome to WebmasterWorld Guest from 54.144.79.200

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Loading external HTML file in every page

html snippet loading, external code

     

hexdj

1:19 pm on Aug 10, 2005 (gmt 0)

5+ Year Member




PHP Newbie here, I am wondering how can I load a HTML into my "every-page" template. Let's say I have a menu (HTML - ul list that becomes a collapsing menu thru CSS) and I want to have it loaded in every page of my site.

I was told this is possible thru PHP, can you guys give me a suggestion?

brendan3eb

1:34 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



<?php
include("page.html");
?>

that should do it. If you want to use php to manage your pages you can use simple bit of code like this:

<?php
$found = FALSE;
if(file_exists("$id.htm"))
{
include("$id.htm");
$found = TRUE;
}
if(!$found)
{
include("error.htm");
}
?>

Place the above code where you want content to appear in your layout and then you can link to html pages appearing in the layout like this - index.php?id=htmlpagenamewithoutdothtm

hexdj

3:56 pm on Aug 10, 2005 (gmt 0)

5+ Year Member



Thanks for your advice, I have been using iFrame to load content on my pages but it does not seem like the right thing to do (I think...?)

Also I have noticed that pages in my website get spidered on search engines and they link directly to any HTML file so people are not able to see menus and other elements

will using-php help me in that users load pages that have been spidered and see them automatically with menus (for example)?

hexdj

9:34 pm on Aug 10, 2005 (gmt 0)

5+ Year Member



I am not sure why but my first DIV is giving me an invalid markup error, also the last </body> and </html> tags show invalid markup. Do I need to initialize PHP somehow in the headers of my index.php file?

this is the body of my index.php

<body>

<div id="topIf"> this one says invalid markup
<?php
include("topframe.html");
?>
</div>

<div id="navIf">
<?php
include("menu.html");
?>
</div>

<div id="contentIf">
<?php
include("home.html");
?>
</div>

</body>
</html> also these two last closing tags

brendan3eb

10:34 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



if your using an html editor like frontpage, then ignore it. That should work fine.

hexdj

1:08 am on Aug 11, 2005 (gmt 0)

5+ Year Member



Actually now I know what it was... I was loading a whole HTML file, with all the <!DOCTYPE>, <body> and <html> tags which -now I know- you're not supposed to do when calling a snippet using PHP.