WordPress – Custom post types and taxonomies

We have just completed a project which redesigned the democracy pages on our website – it is only a version 1 as some of the ideas we wished to implement weren’t manageable in the timescale.

Also with Elections just around the corner we felt it was better to work with a new administration on some of the changes. Like the rest of our public website content will be, the democracy pages have been developed in WordPress.

The previous councillor profile pages were a hybrid of database and manageable content which made it awkward to edit so we made a decision to move the whole lot into wordpress as custom post types and a set of taxonomies.

One of the advantages with wordpress is the ability to adapt it  and present content in ways you want to through new features and functions to create your own custom post types.

In wordpress there are 4 main post types: posts, pages, attachment and links, with the new functions you are now able to create your own post types.

In our new Democracy pages I have used custom post types for Councillor profiles and our new Guides (which were inspired by GDS)

I started by creating a custom post type called Councillors and adding a number of taxonomies to it for indexing and presenting the profiles – these taxonomies included things like – roles, electoral divisions, parish, districts, party etc.

The standard post type only has a number of available fields Title, content, excerpt, featured image. However with another wordpress function you can create custom fields of your own. So I now have a custom post type with all the required fields I need to add all the councillors to wordpress.

One of the nice things with wordpress is you can display the councillors by these taxonomies and the terms you assign to those taxonomies which generated a range of additional and added value options for us when presenting information.

Templates

When wordpress introduced custom post types they also added some extra page templates to the theme. these include a ‘archive’ and ‘single’ templates for the custom post type and also taxonomy template for the terms. In addition you can name the taxonomy template the name of the taxonomy you created so you have the ability to customise the layouts for all taxonomies and the ‘single’ template (councill profile) and ‘archive’ template.

Accessing and links

Unlike other systems wordpress lets you set up a clear url for your site with a clear structure to your pages and custom post types for example:

So you have a clear url structure of the councillor profiles.

In addition to viewing the pages you can also pull the data out of those pages. Natively wordpress gives you RSS feeds and by adding ‘/feed’ to all the links above apart from the councillor page you will get a RSS feed of the councillors – https://new.devon.gov.uk/democracy/councillor/feed.

Another very useful part of WordPress is the plugin and the large community of plugin creators. as a council i decided to find a plugin that would let the councillor data be available in more formats than just RSS. So i went through the plugin repository and found a ‘JSON feed’ plugin. i made some modifications to it to add my custom fields to it and now you can add ‘?feed=json’ to the end of all the above fields to get an output of the councillor profile(s) in a JSON format. https://new.devon.gov.uk/democracy/councillor/?feed=json

Conclusion

To sum up WordPress is a lot more than just a blogging platform, I know it does have its limits as a content management system (CMS) but as it is so customisable you can turn it to whatever job you need it to do. The online community and codex are very clear in showing you how to create some very customised websites and content.

Tim Barrett

I am a frontend developer for Devon County Council. I work mainly on WordPress and PHP.

More Posts

Follow Me:
Google Plus

One thought on “WordPress – Custom post types and taxonomies

  1. Adam Jennison

    A superb example of using simple open source software..
    🙂
    I’m working my way through custom post types for my hyper-local blog and am now enjoying WP as a platform.

    Do you have any thought of releasing your code as Open Source?

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

 

Comments are held for moderation. House rules