I’ve been doing a lot of work recently on my employers website. I had been using Joomla as a content management system, but it was overkill for what I wanted, and I found that it wasn’t the most stable of platforms. (Frequently, and for no apparent reason, pages that were published would suddenly become unpublished.) It was more hassle than it was worth, so I got rid of it and installed WordPress instead.
I decided on WordPress as I’m familiar with it, and with a couple of tweaks to the settings it no longer resembled a blog. It was relatively easy to design a simple template, and get the site up and running, but I did have one major issue. I needed an Events page and a News page to display what would traditionally be considered blog postings . The idea was that each page would be linked to one specific category and one category only. In other words, posts in the Events category would only appear on the Events page and posts in the News category would only appear on the News page.
While WordPress does allow you to specify a static page as your “Front Page” and another page as a “Posts Page”, there doesn’t seem to be an easy way to force WordPress to use two Post Pages, or to restrict a Post Page to just one category. One idea I played around with was to edit the header.php file and manually add the links to the actual categories. WordPress would then display the resulting page using archives.php. It’s then a simple enough matter to edit the file to display the posts as needed. It’s a quick solution but it does pose two problems:
- The links are hard-coded into the header.php file. If for some reason the links are changed, or if the theme is updated, then the links have to be manually changed again.
- Using links in this manner doesn’t give the same flexibility as allowing WordPress to manage the navigation, Pages and Posts.
The answer I found was to use Page Templates. By putting the code to retrieve the posts from each category into a Page Template I was able to bypass hard-coding the links and I could display only the category I needed on each page. If your interested, you’ll find a sample Page Template here.
My next thought is to expand this into a plugin in order to make easier to select which category should be displayed, and which page it should be linked to. I’ll have to think about how to go about it some more though.