Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way of loading content that should appear on every page

Until now, I've been using the <iframe> tag to load things like headers/footers/navbars into my webpage. These cause so much hassle though and as I'm about to start building a new site I thought I'd get it sorted now.

I was thinking of having all the html code in a php file and just loading it in dynamically.. Ideally I'd like the code to become a part of the page. So it appears inline. But I also want to be able to edit one single file if I need to change one bit rather than editing the same file 100 times.

<iframe>'s did this well until recently and I don't want to use workarounds to solve my problems. Could someone please post some code I could adapt or post a link to something that tells me how to do this? Cheers

like image 562
pd93 Avatar asked Aug 19 '12 17:08

pd93


Video Answer


2 Answers

You can use PHP's include() function to include elements like headers and footers in your pages.

So:

include('header.php'); 

. . . will look for a file called header.php in the same directory and include it in your page. Then you just need to write this at the top of your pages.

That said, this isn't really a very good way to go about designing your site. How about looking for a content management system, that allows you to keep the design and content of your site separate?

like image 163
DaveR Avatar answered Oct 20 '22 17:10

DaveR


Are PHP includes what you're looking for ? http://php.net/manual/en/function.include.php

like image 42
Michael Low Avatar answered Oct 20 '22 17:10

Michael Low