Sadly though, many sites seem to be a one time production, with a site being made and launched only for it to serve as a concrete stone in the internet. Things are becoming dynamic, possibilities are becoming endless and with this, site maintenance is becoming ever easier thanks to coding languages and simple methods which are being put to use.
In this article I shall explain 3 of my top tips which I hope will introduce you to new concepts and allow you to continue creating that site which has turned into a chore rather then a hobby. This has been written with the intentions of opening your eyes to a few ideas, not show you precisely how these are done.
Use PHP Includes
When making sites, if done properly, and by that I mean following simple guidelines such as keeping uniform in design, you will often find that pages share a lot of the same code with only the actual content differentiating. The menu, header, footer, statistics etc code will not change between pages so when a change needs to be made, rather then going through every page of the site making changes, why not separate the menu and make it?s code a separate page which is included where needed?
This method means that when a new link needs to be added, only the menu page needs to be modified and from here every other page which is including the menu page will show the menu it?s new form. So if you have 3 pages for instance, you would use the <? include “menu.php”; ?> and each time loaded, the content of menu.php would be included in every page.
A few points, the code within an included page is treated much like the overall pages so variables will be interpolated, functions will be parsed and so on. Note there is also the php function ?Require? which is does the same as include but will exit the script should the file not be found.
Use CSS ? Cascading Style Sheets
CSS is an ingenious idea which allows the separation of content from formatting and allows certain styles / permissions to be set defining html elements, consequently setting the theme of a site which can be edited site wide by making changes to the css.
Put simply, CSS can save a massive amount of time and solves an age old web coding problem, removing the need for the use of any formatting attributes ( such as ?font? ). Using CSS is a simple case of choosing an element and then setting it?s style, a typical css code would look like this:
h1 {
color: blue;
border-left:1px dashed black;
}
A positive point is that CSS is easy to read, with the code above stating that all h1 tags should be of the color blue and have a left border which is dashed, black and a width of 1px. The ?Cascading? term comes from how the styles flow from top to bottom, with inline styles taking priority over external sheets which a later article will go into along with explaining the use of classes / id?s and the 3 different ways of using styles. The most common and recommended is to have an external .css file containing rules which is then linked to in every page you want to follow the styles by using the following code:
<link rel="stylesheet" type="text/css" href="filename.css" />
CSS can style any html element including paragraphs, links, heading tags and many more so be sure to experiment!
Make your code readable
This tip isn?t as important but often overlooked and the cause for many lost hours of frustration. At time of writing code, you know what you want it to do and how it shall work, but a month down the line returning to the page there?s a good chance you will feel lost and find a reason to leave it untouched.
What I often to is format my code so lines to not run past my screen resolution, so all can be seen, making things easier to understand. Remember that white space in source is ignored so use this to your advantage.
A final important factor is commenting! CSS, PHP, HTML .. infact every type of coding language can be commented and should be put to use whenever code is written that wouldn?t be immediately obvious.
<!-- This is how to comment in html -->
// This is how to comment a single line in php
/* This is CSS commenting */
This is also a great way of teams working on sites, leaving comments / notes so other staff members know what position you are at, what certain code does etc and allowing for further development.
I hope this article will save you time updating in future and has either refreshed your memory or taught you something new to improve your efficiency as a web developer!
