[box type=”note”]Important: Your web server must support PHP in order to use the information outlined below.[/box] [box type=”download” icon=”empty”]Please note: This articled is provided as a guide but this modification is outside the scope of TrueThemes customer support. We are unable to provide further support for this modification however if you need expert coding assistance we highly recommend http://www.wpqustions.com [/box]
This article outlines how to convert certain areas of your Karma HTML Website Template into PHP Includes. PHP Includes are beneficial because they enable you to make site-wide updates by editing only a single file. If you’ve never worked with PHP Includes we highly recommend checking out this article before proceeding: http://www.htmlandphp.com/beginner-php/introduction-to-php-includes.html
Here’s a quick overview of the modifications required:
- Decide which areas of your website are suitable for a PHP Include
- Create the PHP Include(s)
- Rename each file in your website from ‘.html’ file to ‘.php’
- Add the PHP Includes(s) throughout your website
Step 1: Decide which areas of your website are suitable for a PHP Include:
Suitable areas for a PHP Include are areas which have “the same content” throughout every page in your website. This can include things like Footer Copyright information, Footer Navigation, etc. In this tutorial we will outline how to turn the Footer Copyright and Footer Navigation into a PHP Include.
Step 2: Create the PHP Includes:
- Open up an existing HTML file within your website (ie. template-leftnav.html)
- Scroll to the bottom of this file and copy the HTML code responsible for Footer copyright and navigation. (see screenshot #1 below)
- Create a new file in your code editor and paste in the HTML code you just copied. This file should contain only the HTML code copied and no other code.
- Save this new file as a PHP file. In this example we will save this file as: include-footer.php
Step 3: Rename each file in your website from .html to .php:
PHP Includes can only be called from within a PHP file. This step requires you to change each HTML file within your website from ‘.html’ to ‘.php’. In this example we will rename template-leftnav.html to template-leftnav.php. This process will need to be repeated for each HTML file within your website.
Step 4: Add the PHP Includes(s) throughout your website:
We now need to add our newly created PHP Include to template-leftnav.php
- Open up template-leftnav.php in your code editor.
- Scroll to the bottom and locate the “Footer Bottom” HTML code which we copied in step 2.
- Remove the HTML code and include our PHP:
&lt;?php include 'include-footer.php'; ?&gt;
Our static HTML code has now been replaced by a PHP Include. We will repeat this process throughout our entire website. The quickest way to do this is to use our code editor’s “find and replace” function. We will “find” the Footer-Bottom HTML code and replace it with our PHP Include above. Updating the Footer information in our website will now a much smoother process. Anytime we want to update our Footer information we will only need to modify the single include-footer.php file.
We highly recommend checking out our Karma WordPress Theme. WordPress is an incredibly powerful platform that uses PHP and Databases to pull in our content, and it will do all of the below steps along with a vast amount of other awesome functions making it super-easy to maintain our website. Karma WordPress Theme →