From Weblog to CMS with WordPress

With the advent of blogging software, creating web pages has become so easy that anyone with the most basic computer skills can establish a presence on the web. However, in the best open source tradition, the most popular blogging software is evolving rapidly. In some cases, it is now as powerful as many of the content management systems (CMSs) used to build traditional websites.

This article describes how we used one blogging package (WordPress) to replace a traditional content management system (phpWebSite) to run a community website. As a result, ordinary people in the community can now maintain the site, the site has all sorts of new features such as RSS feeds, and the webmaster can do more useful things (such as hacking WordPress plugins).

Why a Weblog?

For those who have been living on a different planet, a weblog (or blog) is an online diary that contains a series of posts displayed in date order (newest first). In addition, blogging software usually provides an archive mechanism for filing away old posts, permalinks (human-readable URLs for each post), some means of classifying posts, a search engine, RSS feeds, and other goodies. However, the key factor is ease of use for web novices: allowing the creation of web pages using a WYSIWYG editor and without requiring any knowledge of HTML, CSS, FTP, or other acronyms.

There is a wide range of open source blogging software available. WordPress is one of the more well-known and most powerful blogging packages. It runs on a standard LAMP platform and it has a very open architecture, so it is highly configurable by skilled users. However, version 1 was criticized for putting the power in the hands of skilled users at the expense of ease-of-use for less skilled users. WordPress 2, released in the beginning of this year, has gone some way to remedy this, with a decent WYSIWYG editor (TinyMCE) and other immediately available features, such as the ability to upload images (see Figure 1).

After using WordPress to create my blog, I wondered whether it would be powerful enough for a "real" website. I have been maintaining a community website for the Balerno Community Council for more than five years, migrating the content between several platforms, most recently phpWebSite. phpWebSite is a great CMS, but it has proved a challenge for ordinary people using it to maintain content. WordPress looked much easier to use, but would it work as a CMS?

A Better Theme

My first problem was that I have zero graphic design abilities. Fortunately, there are many WordPress themes out there (see Resources at the end of this article). After a bit of hunting around, I found Becca Wei's WordPress themes -- her Almost Spring theme was pretty close to what I was looking for. Although it was a WordPress 1.5 theme at the time, I found it worked perfectly well with WordPress 2.0. With a bit of fine-tuning, I had the look-and-feel I wanted.

Next, I had to make WordPress work like a CMS. The first clue that WordPress might do the job was its support for static web pages. WordPress provides the usual chronological blog posts (called "Posts"), but it also understands traditional web pages (called "Pages" -- there's an original naming convention for you). You can arrange pages in a hierarchy, with child Pages listed beneath a parent. Pages are essentially static; once you put them on the site, they stay there and don't disappear off into an archive. That sounded like a CMS to me.

I now needed to find a way to use one of these Pages as a home page, which would be displayed in a different layout from the other content pages. WordPress supports multiple templates, which it calls a template hierarchy. By default, WordPress uses an index.php template file to display content. However, you can overwrite this when displaying certain types of content, such as archive data or the author's personal profile. The feature I needed was that when WordPress finds a home.php and an index.php, it will use the home.php template instead of index.php whenever a user accesses the root URL of the site. Another problem solved.

The next challenge was creating a home.php that would display only my selected home page. Becca's theme had given me a wp-content/themes/almost-spring/index.php, and copying this to home.php created a starting point for hacking. WordPress helpfully provides a Theme Editor to make hacking possible without having to go through the "FTP it down from the site, edit it, then FTP it back again" routine, but you still have to hack the code (see Figure 2).

Figure 2. Hacking code the WordPress way (click for full-size image)

How it Works

This is how my hack works. WordPress's default index.php template file displays the last n Posts, which index.php receives through a mechanism that the documentation calls "The Loop". This creates a traditional blog. The home.php hack replaces The Loop by a single selected Page. Suddenly, I no longer have a blog -- I have a conventional website.

The hack can be summarized in four easy steps:

Find a theme and do any fine-tuning

Design the home page as a Page in WordPress. Give it a post-slug of home. Test that it looks ok.

Now, when visitors access the home URL, WordPress will display only the Page with a page-slug of home. It's no longer a blog -- it's a website.

What is a page-slug? If you choose to enable name-based permalinks, WordPress will create a URL-friendly version of a Page title (for example, "My Home Page" becomes "my-home-page"). This is a page-slug. WordPress allows you to overwrite the default with your own pet slug if you so desire.

What is query_posts?query_posts is one of the many WordPress template tags, which bridge the worlds of the HTML designer and the PHP hacker. Please read the documentation for more.

Once I had the home page sorted, designing the rest of the community site was comparatively straightforward. The site contains about a dozen pages of general information, which are WordPress Pages, and also snippets of local news and minutes of meetings going back eight years, which are now WordPress Posts. It's a nice twist that WordPress was originally designed to manage Posts, with Pages as an afterthought. In this community site, the main content of the site is Pages, but it also makes good use of Posts.

Could WordPress be used for full-blown websites as well as blogs? I believe the answer is definitely yes. WordPress lets users do an awful lot of things without requiring any knowledge of the underlying technology, such as maintaining content, including images; creating categories for the content; selecting the look-and-feel of the site from a large and growing range of templates; managing multiple users with different access rights; and adding and removing plugins for extra functionality. For users with a working knowledge of web technologies such as HTML, CSS, or PHP, then so much the better -- they can dive under the bonnet/hood (depending on which side of the Atlantic you dive from) and work all sorts of magic. The end result is the best of both CMS and blog worlds, with flexible content layout arranged under hierarchical menus such as a CMS, plus all the nice features of blogs such as ease of maintenance, RSS feeds, comments, and permalinks.