This article is intended for PHP web developers who create template systems to present website content in a consistent manner. PHP designers creating their own template systems need to be concerned with how their choices affect the website’s search engine ranking. Following is a discussion of three types of systems, their impact on search ranking, and a recommendation for the best approach.
Web page as CGI plot
In this architecture, a PHP script contains the full template and connects the contents of a file that it reads, getting the filename from a CGI parameter. These types of systems are not only prone to security issues (since users can modify the path argument to retrieve arbitrary files), they are also ineffective for search engine optimization.
This particular design does not allow titles and keyword/description meta tags to be associated with individual pages. This is because the header part of the template includes the section within it and only allows one site-wide title and set of meta tags. Titles are one of the most important page elements, and having a title, unrelated to the actual content retrieved, results in lower search engine rankings.
There are two other detrimental SEO effects that this type of system has. The first is that each unique page looks like a appearance from the template script, rather than as a single stand-alone page. This can lead to search engines downplaying the importance of individual content pages relative to the template script, which is often not the desired result. The other weakness of this approach is that having individual pages set as CGI arguments makes site metrics more difficult to track, as stats often show a specific page hit as a hit to the overall template script. The popular web statistics packages AWstats and Webalizer are the most affected by this.
However, this type of template system is popular and successfully used in the world of e-commerce. In such systems, product information is stored in a database and inserted into the template when a product is requested by its code. This means that both a single title and a set of meta tags can be stored alongside the product data (or generated on the fly) and effectively inserted into the global template. The only detrimental effects that remain are the last two mentioned, and these are generally an acceptable trade-off for the greater ease of administration provided by a database-based system.
Template as Include
In this architecture, each page of the website has its own filename with a .php extension. The top and bottom parts of the template are stored in separate files that are included (using include_once() ) in each content file. This technique increases the importance of the page with search engines, as each page is its own separate page rather than a CGI argument. This type of template system also makes it easy to track page views through regular website analytics software.
On the other hand, this type of template system still has the weakness of having one title and set of meta tags for the entire site. This is, again, because the header part of templates must include everything from the opening of the tag to the end of the code for the header part of the template. And this area includes the title and meta tags. One solution for this type of system is to hardcode the top template page to check which file it is being called from and replace it with a suitable pre-coded title. While effective, such a system is cumbersome to maintain, as each new page that is published requires a new title and meta tag entry in this secondary system.
Includes body only
The ideal PHP template system will allow content producers to enjoy template reuse while maintaining unique titles and metadata for each page with ease. The system that meets all of these SEO needs is a “body-only include” system: a system where each page of php content includes the top and bottom of the template (as in the approach above), but only includes the items below the Body label. This results in a document that has its own html, head, title and meta tags, you have an include_once() statement that is called at the top of the Body element and includes the top part of the template, it has the content and an include for the footer part of the template. Such a system allows individual editing of title and meta information during document creation and solves the problems faced by the two mentioned systems.
I find this system to be the most search engine friendly, because it keeps the title and content information together, allowing for unique and relevant titles for each page. This system is also the most human friendly, as storing the title information in the same file as the page content allows for quick updating and avoids maintaining a second “workaround” system that tries to match titles to the content.
conclusion
The types of template systems that PHP developers choose to implement for client sites have a crucial impact on the future popularity of client web pages in search engines. Important factors to consider when developing a template solution are: relevant titles linked to content, relevant meta tags, separate files, and ease of tracking statistics. The popular page-as-argument and template-as-include approaches do not provide these functions effectively. Include template information after the Body and keeping headers intact is the best way to ensure sites are optimized for search engines, which is why you should consider using the included body-only model during your next project.