January is Theme Month

In January 2009 I will be concentrating on themes and themeing.

Got a theme question, or conundrum? Let me know.

Don’t mess with my Toot Toot

Last night a question was asked on twitter about the potential for adding alternative content types for WordPress. I replied.

I went so far as to suggest that it should be pretty easy to add a new content type and in return received a challenge, and this post is the result. I have written a plugin to add a very simple new type of post and I am going to try and explain the component parts of that plugin here. I don’t intend to include a lot of code; my intent is to explain the general process that I used, but the plugin will be attached to the end of the post for them that want to see how I did it.

There may be better and easier ways of doing it than this but this is my version.

What I decided to create

I needed this really simple. The point of the plugin was not to make a finished article but just to demonstrate how to, so I decided to create a twitter clone of sorts. Two fields would be editable, title and content, the content would be limited to 140 characters, and there would be no drafts or editing. Adding and deleting only.

These new posts would be called Toots.

Defining the new post type

To add a new type of content there are really two options: create a new table, or use the existing posts table.

The posts table was fairly recently amended to allow alternative post types. This, in combination with the fact that there are already a lot of functions that can be used instead of having to write my own made it a no-brainer for this exercise. I haven’t used any database code at all.

Adding a different type of post is very very simple. Once all the form handling, and validation is removed this small function is what actually makes the magic happen:

function new_toot( $title , $content )  {
	global $user_ID;
 
	//get the relevent post vars and save away
	// Create post object
	$my_post = array();
	$my_post['post_title'] = $title;
	$my_post['post_content'] = $content;
	$my_post['post_status'] = 'publish';
	$my_post['post_date'] = date('Y-m-d H:i:s');
	$my_post['post_author'] = $user_ID;
	$my_post['post_type'] = 'toot';
	$my_post['post_category'] = array(0);
 
	//Insert the post into the database
	return wp_insert_post( $my_post );
}

All that really happens here is that I create an array and pass it to wp_insert_post. A function that already exists in WordPress. Deleting a post is even easier.

Managing this content means adding a new write panel and a new manage page which respectively pass commands to the plugin and trigger the add and delete functions. So far so simple.

Theme pages

The next part of adding new content types is new theme pages, and defining a hierarchy of theme pages. So first it is necessary to create a custom URL.

I’ve written before about the process of creating a custom URL but there are effectively three processes involved:

  1. Tell WordPress to flush out the existing URL rules
  2. This triggers a process to reacquire them, at which point you can insert the new rules
  3. Add to the list of query string values that WordPress looks for, so you can use this to make decisions later

So when a user enters blogname/toots/19/ for example you can access this with $wp_query->get(’toots’) and use it to make decisions.

With that data available the template selection process can be interrupted and if a specific toot has been chosen, as per the URL above, a single toot page can be served and if toot is selected without an ID a toot archive can be served, or it can fall back to the home page, or archive page.

Displaying the content: creating a loop

Obviously this is all academic if the content can’t be output, so we need a loop:

When WordPress first loads the plugin creates a new query, in the same way as posts are created, but instead stores them in the $toot_list global variable, instead of the $posts global variable.

When the template selection happens, if a specific toot has been selected then a new query is carried out that replaces the current list, so only one toot is available.

The remaining functionality is handled by a list of functions that access the $toot_list global variable. I won’t list them all but the key ones are included here:

have_toots

This replicates that have_posts function that is part of the loop. It checks the global $toot_list to see if there are toots to display.

the_toot

This is the second part of the loop. This gets the next toot and makes it available to the other functions using the $toot global variable. This is equivalent to the $post global variable.

So the toot loop looks like this:

if (have_toots()) : while (have_toots()) : the_toot();

You can see it is practically the same as the normal post loop, but with toots instead of posts.

the_toot_title

The is the equivalent the_title, it echos the title.

the_toot_date

The it echos the date.

the_toot_content

The echos the content.

the_toot_rewind

The echos the content.

So a full loop might look like:

<?php if (have_toots()) : while (have_toots()) : the_toot(); ?>
<h3><?php the_toot_date(); ?>: <?php the_toot_title(); ?></h3>
<p><?php the_toot_content(); ?></p>
<?php endwhile; ?>
<?php endif; ?>

There is obviously more that would be done to make a fully complete new content type but hopefully this demonstrates how you can go about it, should you want to take things further.

Download

The plugin can be downloaded here.

What do Content Management Systems have that WordPress doesn’t?

Include WordPress in a list of content management solutions and the “WordPress aint a CMS” comments will surge forth as inevitably as water flows toward the sea. But what is it that makes one piece of software a Content Management System, and another a lowly blogging tool?

My opinion, for what it’s worth, is that people expect a CMS to have feature X or N and as a result will classify any software that doesn’t have it as something else, but is that a mistake? I have always been in the camp that says that if you can manage content with it, it is a content management system, and therin lies the problem. Can you manage content with WordPress, or just publish it?

Before I go any further it is worth considering what the owner needs. For a very small business most traditional content management systems are massively over-specified. I think this is probably true for most small and medium sized companies as well. As you look at the features WordPress lacks consider what kinds of business are actually going to benefit from them.

With that said, let’s move on.

User management

The most obvious requirement is good user controls. With WordPress you can specify who can create a page and not publish it. This is a start, but can you limit an individual to posts within a particular topic, give them publish access in some places but not others?

There is certainly scope for better controls, but for small businesses the controls that are already there may well be sufficient.

Version Control

WordPress was long criticised for the lack of version control, and it now has it, but it is fairly basic. While WordPress can certainly help make sure nothing is lost, and allow you to compare one to the other as an audit tool it is limited.

Again a good question is how much control is needed? If you want to use your CMS as your audit trail then WordPress won’t cut it, otherwise it is probably enough.

Workflow Management

A key part of a content management system is the workflow tools. WordPress separates writing and editing but there may be more steps in the process: author, designer (editor, formatter, call it what you will), PR sign off, information architecture, etc. Larger businesses may have several different people that must sign off on the content. You may also need review and expiry dates when content is automaticlaly removed. WordPress doesn’t do that.

One workflow feature that I have always wanted (although not enough to develop it myself) is the ability to create an entire site based on draft content. Financial services firms (an no doubt many other industries) must gain approval from a qualified person within an organisation before publishing. If you make big changes, looking at a page at a time without the ability to navigate around can be painful.

Once again though, how many businesses actually need this, and how many only want it because it is available from other systems?

Menu Control

This for me is a biggie. Where is the option to create and control site menus? Listing all the pages is not an option in a working site as there will inevitably be pages you do not want in the list. If I used WordPress for a client CMS this is something I would need to create before going any further.

Form Builder

There is a great plugin that does everything you would ever want to do so it isn’t an issue, but the fact that it isn’t in core when many more basic things are being added tell you that WordPress isn’t moving toward business users, but away from them.

In writing this I looked at a lot of other functionality offered by content management systems but frankly most of it seems to be very situation specific. The kind of features that no one knows they want until they are offered it. How many companies really need banner ad management?

So, having considered these things do I still think that WordPress is a content management system? No. I think it is a content control system, or a content publishing system, but I do think it is enough for most companies provided they can put in place their own management processes. Having said that, blog content is still content, no? My opinion on most complicated CMS systems is that they are trying to throw a software solution at a people problem. WordPress can do anything you want with the right plugins but even without them I would take it over the alternatives.

I know what you read last week!

Everytime you select a category, tag, archive or post from a list you are indicating a preference, but blogs aren’t yet making use of these indicators and I think it is time they did.

When you find a new blog you often end up navigating through it to see what else is on offer, but that is a fairly random process. You might not be searching for anything in-particular but your habits will certainly indicated your interests and there are ways for blogs to use that to your advantage.

If, after reading the first post, you click on an archive to read more then you are indicating that something about the initial post was probably interesting enough to make you want more.

If you select a category or a tag then you are expressing an interest in that topic, and if you select a post from a list then you are expressing an interest in the topics represented in the title or excerpt of that post.

By tracking your movement through the blog and adding each choice to a profile the blog can begin to identify which posts are more likely to interest you and promote them to the top of lists.

Knowing which posts you have already read also helps to keep the suggestions fresh.

Would you like to see blogs that anticipate your interests? or would you rather just browse and hope?

Categories are not necessary

Ever since I have been using WordPress it has been based on categories. Tags are a relatively new thing, that I have never used, and even newer in the core. Interestingly Habari currently has only tags and I think this difference is quite an interesting one.

Generally people tend to think of categories fairly strict divisions that define the main topic of a post and tags as more specific, but loosly used, labels that are actually closer to index entries than an organisational structure.

The nature of blogs means that it is rarely possible to pre-define the content that will be included and this means that categories often get a little overgrown and need pruning back once in a while. Tags on the other hand are much more fluid and so can be left to grow where they will.

When it all comes down to it though they are both labels that apply to content. The only difference is in the way that we think about them, and use them. In fact the biggest difference is the user interface.

I’ve spent that last month doing little else but organising information and trying very hard not to assign lables to the various parts of the hierarchies so as not to confuse people with terms they expect to refer to something else and even so it has taken me some thought to get my head around the difference, or lack of difference, between tags and categories.

Only using tags (or only using categories) seems to offer a lot of flexibility. It lets you use plugins and naming structures to create hierarchies without the need for WordPress or Habari to actually be written to meet individial needs.

The differences, and uses, of tags and categories are well ingrained in people’s minds now and, let’s be honest, a lot of people do not want to consider their site taxonomy in greater depth than the default provides, but I think it would be interesting to just stop using categories in WordPress and switch to tags. It would certainly simplify some things.

 Page 1 of 3  1  2  3 »