Custom WordPress Page Templates

WordPressCustom templates are becoming the key factor for any content management system out there. Possibility to create a custom front end lets many developers create their own custom templates. But have you ever had the need to create a custom template for a specific page on your WordPress-controlled website? Maybe you have created a page on your site that needs to include a customized sidebar, or maybe you want to create a custom archive page for specific categories of blog posts? Whatever the reason, it’s something I am constantly doing within my WordPress websites.

So, how is it done? Well, there are actually quite a few different ways to develop a custom page template for WordPress.

WordPress: Style Top Level Pages Differently

Recently, I needed to figure out how to apply different styles to the top level pages on a WordPress site than those applied to child pages. After a little digging, I figured out a fairly easy way to determine which is which.

Granted, I could easily create a custom page template and assign it to each of my top level pages, but that would require anyone creating new pages to recognize whether or not the custom template is supposed to be applied, and that change would have to be made any time a page is moved.

Instead, I wrote some simple functions to check whether or not a page is a child page or not. I then use that function to assign a specific class to the elements that need to be styled differently.

Integrating WordPress into dynamic templates

I installed a WordPress blog on my development server the other day and began playing with it. The first real challenge I faced was how to pull my WordPress installation into my Web site’s template.

My issue is, I’m using a content management system (CMS) to manage the bulk of my Web site’s content. However, I wanted to use WordPress to manage my various blogs. I obviously wanted my blogs to look like the rest of my Web site, so I needed to come up with a plan to integrate my WordPress installation into my CMS, somehow.

Basically, what it came down to was that I needed to find a way to store all of my WordPress output into PHP variables. Once I had done that, I could plug those variables into my template. The main problem I ran across, however, was the fact that 99% of the functions WordPress uses to build its output utilize echo commands rather than simply returning the output.

That was no good for me, obviously, as it started printing content onto my page before the template had been processed.

PHP came to my rescue, and with very little headache. PHP’s output buffer was the simple answer to my problem.