2

As the title says, is there a way to edit a portion of an entire site with one code or page? For example, if the bottom of every page of a site said "2014", is there a way in html or css to change every page of the site to say "2015" without having to do so manually to each individual page?

I understand this can be done in php, and I understand that a server can be configured for html to read php code. Are there any flaws to this method (perhaps the html page will load slower if it's configured to read php)? Are there any other ways to do this besides using php code?

jamiestroud69
  • 277
  • 1
  • 12
  • Well that can be done with jQuery, you need to have a Base page that is shared by each page. As in .net we have Master /Layout page. I will let you know how can you do this with jQuery if you are interested? – Manoz Apr 05 '15 at 08:40
  • You can do it in two ways. 1) server-side 2) Javascript 3) Not sure but css `content` may be used too. – codename_subho Apr 05 '15 at 08:44
  • @Manoz Is the jQuery method similarly as efficient as the php method that FactoryAidan posted? I'm curious to know it if it's not too much trouble for you. – jamiestroud69 Apr 05 '15 at 09:09
  • @user3174538, jQuery is client side script for performance comparison wise this is the quite well to use. – Manoz Apr 05 '15 at 10:37
  • If you go the jQuery route look at [this answer](http://stackoverflow.com/questions/4886319/replace-text-in-html-page-with-jquery#answer-4893386). – wavemode Apr 05 '15 at 22:15

3 Answers3

2

Performance Concern:

You will not see any performance difference between having PHP render basic HTML and typing the HTML yourself.

The performance impact is only noticeable on HUGE PHP applications. And even then, it's still very fast.

What you ask is common practice. This is an example of what you can do.


Make a file called index.php and put this inside:

<!doctype html>
<html>
    <head>
        <!--Your head stuff-->
    </head>
    <body>

        <header><?php require_once 'header.html' ?></header>

        <section class="main_content"><h2>My Page!</h2></section>

        <footer><?php require_once 'footer.html' ?></footer>

    </body>
</html>

Make a file called header.html and put this inside:

<h2>This is my header</h2>

Make a file called footer.html and put this inside:

<h2>This is my footer</h2>

As you can see, the practice is to use any of the built-in PHP functions to include other files in your PHP file:

include 'some_file.php';

require 'some_file.php';

require_once 'some_file.php';

FactoryAidan
  • 2,484
  • 1
  • 13
  • 13
  • This is a much simpler and more efficient way to do it than the jquery methods I looked at. It's puzzling to me why so many people speak poorly of php. – jamiestroud69 Apr 26 '15 at 08:06
0

I think Dreamweaver can do this, with its find and replace entire website property

sanu
  • 1,048
  • 3
  • 14
  • 28
0

Assuming all pages have a CSS file in common, you can use the content CSS property of a pseudo element like before or after to control content across all pages.

For example:

#footer:before {content:'2015';}
<div id="footer"></div>
Boaz
  • 19,892
  • 8
  • 62
  • 70