homepage Welcome to WebmasterWorld Guest from 54.211.95.201
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Loading external HTML file in every page
html snippet loading, external code
hexdj




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


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




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

<?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




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

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




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

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




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

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

hexdj




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved