condoravenue Posted December 9, 2010 Share Posted December 9, 2010 Hello, I have recently discovered that you can make sitewide content using the php function get_file_contents(), if you put html code in a separate file. My site's header, navigation, and footer all use this function. This makes changing the layout of your site about 50 times faster, since you only have to edit a couple of files, rather than every single page. Look at my example. The code for each page will look like this, so that I only have to edit the content. <?php $file = file_get_contents ("header_and_navigation.php"); echo $file;?> <p>Content goes here.</p> <?php $file = file_get_contents ("footer.php"); echo $file;?> header_and_navigation.php may look like this: <html> <head> <title>title</title> </head> <body> <div class = "header"><h1>Title</h1></div> <div class = "navigation"><a href = "home.php>home</a><a href = "about.php>about</a></div> while footer.php may look like this: <div class = "footer"><a href = "contact.php>contact</a><a href = "terms.php>terms</a></div> </body> </html> I thought of this on my own. No one ever suggested I do it this way. This leads me to believe that there must be a downside to it. What do you guys think of it? Quote Link to comment https://forums.phpfreaks.com/topic/221110-creating-sitewide-content/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 9, 2010 Share Posted December 9, 2010 Usually include is used to do this so that any php code in the file will be parsed as php code. Quote Link to comment https://forums.phpfreaks.com/topic/221110-creating-sitewide-content/#findComment-1144899 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.