Jump to content

Creating Sitewide Content


condoravenue

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/221110-creating-sitewide-content/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.