Custom Post Types in WordPress 3
With the addition of custom post types, WordPress 3 can finally hold its own against its rivals in the CMS market. I’ve previously used custom fields a whole lot during projects to separate content and allow clients to manage this content a bit better, but thanks to custom post types we are now able to make adding content to a site a really simple process and the client no longer has to worry about which custom field they should be editing.
While I wouldn’t say custom post types are an ideal way of labelling blog posts (this is what categories and taxonomies are for) they are ideal for giving you much more control over what content you can edit in a post.
Set up custom post types
Setting up the custom post type couldnt have been easier. Crack open the functions.php file in your WordPress theme and add the following code:
add_action('init', 'work');
function work() {
$args = array(
'label' => __('Work'),
'singular_label' => __('Work'),
'public' => true,
'show_ui' => true,
'menu_position' => 5,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes', 'excerpt')
);
register_post_type( 'work' , $args );
}
This is a pretty bloated example of adding a custom post type but there still isn’t too much to take in. We have added the post type named “Work” and an array of arguments. There are lots of arguments added in this example but you can set up your custom post type with as many or as few as you like (view the full list of arguments at the WordPress Codex)
At this point you have just created your new custom post type as you can see below. This is its most basic form allowing you to create posts with a title field and a content area.

Display your single posts
Next you will want to display the singular view of your custom post type on your website. The best way to do this is to create a new template in your theme. WordPress will usually use single.php to display your posts as default. To add a custom template in its most simple form, duplicate single.php and rename it with the name of your custom post type after the word single. For example, in my theme the custom post type is called work, so the name of the template is single-work.php. You can create a different template for every custom post type you create.
Its just as easy to list these posts in any of your templates using a custom query such as in this basic example below:
<?php query_posts("post_type=work");
while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink () ;?>"><?php the_title(); ?></a>
<div><?php the_excerpt(); ?></div>
<?php endwhile; ?>
Expand upon the custom post types
The name says it all really, CUSTOM post types. So surely you will want them to be customised and different to standard posts. This is where we can get creative and really polish the user experience.
In the example below I created several text fields and text areas in the Work custom post type. I wanted to allow to client to easily add job titles, client names, a box which would display client feedback and a section where they could embed Vimeo videos without having to fiddle about with custom fields.
To add a new text field into the backend of your custom post type modify the following code to suit your needs:
<?php
add_action("admin_init", "admin_init");
add_action('save_post', 'save_custom');
function admin_init(){
add_meta_box("workInfo-meta", "Thumbnail", "meta_options", "work", "side", "low");
}
/* Thumbnail Field */
function meta_options() {
global $post;
$custom = get_post_custom($post->ID);
$thumb = $custom["skt_thumb"][0]; ?>
<input name="thumb" value="<?php echo $thumb; ?>" /> <?php
}
function save_custom() {
global $post;
update_post_meta($post->ID, "skt_thumb", $_POST["thumb"]);
}
?>

In the above example we have added a meta box into the admin area with a title of Thumbnail, positioned in the right hand side of the page in the backend. This custom field has a key of skt_thumb. For a full description of all of the parameters used in this string take a look at the WordPress Codex page
Using a standard get_meta_post we can call the data from theses custom fields into our template and display them beautifully!

There really is so much more to custom post types than what I have sketchily described here. They have opened up a whole new way of handling content in posts and hopefully you will play around with them and find loads of interesting ways to make WordPress work better for you and your clients. At Substrakt we’re loving them and looking forward to putting them into practice in our new projects.
404 errors in WordPress 3 theme files
In the move to WordPress 3, I’ve discovered an interesting, hitherto unknown “feature” which, if you’re building AJAX functionality into your themes or plugins, may cause a headache or two. It’s an easy fix, once you’re aware of the issue.
Design, Design, Design
Okay, the last couple of months have been pretty busy here at Substrakt HQ and I guess that’s what I intend to blame my lack of blog posts on! So, I hear you ask, what have I been up to?
Plenty! Amongst moving to Moseley, Substrakt day out, Glug London, Creative Coffee meetings, Digital Playground, trips to the Electric, exhibitions, birthdays, weddings, Centre Parcs and a wonderful holiday to Mykonos, I’ve had the opportunity to work on some really great projects.
After our Substrakt day out we managed to share a lot of thoughts and ideas on how to develop our creative processes and ways to work in which we would benefit from each other’s talented skill sets. During this Ryan and I realised we shared many thoughts on design direction and that working closer together on projects would be beneficial to both us and the client.
Since then we have had the opportunity during numerous brainstorming sessions along with Jim to exchange knowledge and opinions on many of our projects whether it be branding, digital or print. It’s great to be part of a creative team sharing my passion for design and once our new site has launched we will be integrating this to share with you!
Here’s a little sneak of some projects we’ve been working on recently and until our new site arrives you can check out my daily inspirational posts here.
Adobe <3 Typekit
2 days ago Typekit announced that Adobe was joining it’s ever expanding roster of font foundries. For those unaware, Typekit is a way of getting more attractive fonts on your website, but in a more accessible, legal way. Fonts on the web have always been a hit and miss subject. You either go with images, cufon, sIFR etc (flash and javascript rendering) which have drawbacks, or go with the font’s you know most people will have (Times New Roman, Arial etc).
In the last couple of years however services like Typekit have popped up, allowing webdesigners/developers to embed a vast range of fonts on a website, but remain fully selectable and legal. Most ‘uncommon’ fonts don’t allow for embedding on websites, or just don’t include the licensing terms for such things, so it’s a bit of grey area. Typekit (and similar services) however deal directly with the type foundries, allowing you to use nicer fonts on the web for a subscription, which pays the foundries for the right to use them on the web. Everyone wins!
So what does Adobe bring to the table? Quite a few nice fonts actually. Some of my favourites of the bunch are Myriad Pro, Caflisch Script, Minion and Rosewood Fill, but many more. This also injects confidence in these type services if a heavyweight like Adobe is getting on-board. So hopefully eventually, any font should legally be available to use on the web (within reason). One question i’ve wondered though. How are some clients going to respond to paying a yearly subscription for fonts, when there are so many free ones available?
Here’s a link to the Typekit press release.
Another 48 hours
Last year I organised and took part in a socially-aware hackathon called Hackitude, with the idea of building something cool in 48 hours. Last weekend I competed in Django Dash, a 2-day contest for Django developers.
When Old-Skool is Useful – Image Mapping
Several of the sites we have built and maintain have Flash maps embedded within them, and occasionally these maps need updating. The Willowbrook Shopping Centre map in particular is frequently updated as businesses join or leave the centre. The trouble is, opening an old Flash file and spending half an hour remembering how to edit the thing is not the most efficient way of updating something as small a link or removing a store from the map.
With this in mind and an update due to the website I decided it was time to recreate the Flash map in HTML and CSS. Of course, armed with HTML5 and CSS3 this would be quite a pain free task, but supporting IE6 and 7, I was not so fortunate. The main bulk of the map was easy enough to build up as the elements were square and easily placed using absolute position, but a section of diagonally placed elements, and some strange corner shapes meant that I couldn’t set anchors without overlapping other links.
Desperate to not have to resort to Dreamweaver’s useless image mapping tool, I found a really useful (albeit ugly) website for image mapping, image-maps.com. While this website is totally stripped back in terms of design, it does exactly what it says it does; maps links to images. And it does it well, and really easily. Just upload your image, plot the points by clicking on the image, and save out the code.

This solution saved me a shedload of time trying to manually plot the image maps, and also meant that I could create a tidy pure HTML and CSS interactive map that is fully functional on the dreaded Internet Explorer browsers!
The moral of the story is, sometimes the old tricks are still a perfectly valid way of solving a problem. If it wasn’t for the dated image mapping method I wouldn’t have been able to fix this problem. Oh also, don’t judge a book by its cover. Really ugly website, but saved my skin!
be2camp 2010
I attended and presented at Birmingham’s be2camp yesterday at the Library Theatre. The event was extremely well programmed and organised by Rob Annable (Axis Design) and Lorna Parsons (BPN Architects, RIBA and MADE). The morning session was focused on the new Library of Birmingham project and saw informative talks from Brian Gambles (overview), Peter Marsden (mobile technology) and Tom Epps (virtual library).
Be2camp is for people interested in how the latest web applications and web design techniques (Web 2.0; eg: RSS, blogs, Twitter, Wikis, etc) could help build a better, more sustainable built environment – planning, design, construction, even occupation and management of buildings, infrastructure, landscape, etc.
One presentation that really impressed me came from James Thompson from Buro Happold who spoke about the use of BIMs (Building Information Modeling).
Meshed Media have summarised the event in their blog post.
My presentation detailed a couple of projects and concepts we are working on that explore the use of digital media within the built environment.
- The Golden Square project in Birmingham’s Jewellery Quarter, where we have been commissioned to develop a digital visitor centre, accessible via the web, mobile devices and touch screens at the new public square.
- Library of Birmingam digital wayshowing application
I also explored the concept of space surfing, being able to navigate a space and/or place as you would the web, allowing the exploration of city to be based on your particular interests to improve user experience.
Substrakt is really excited about the potential of using some emerging technology within this field and exploring the use of data pertaining to actual public spaces and buildings.
Below is a copy of my presentation. I used Prezi for the first time and quite enjoyed it, a good way to dump all your points / assets on to one canvas and then create a path through the presentation. It could potentially make you a little dizzy though, so be warned! Click the play button and then press your right arrow key to navigate through.
Hat tip to Tilt shift CSS3.
Here at Substrakt we love a bit of emerging technology and CSS3 is especially close to our hearts just for the sheer possibilities it presents. At the moment it’s just that ‘little extra’ for people with the latest and greatest, but it’s potential, when widley supported, is epic.
We’ve all seen the numerous impressive ‘icons made with CSS3‘ tech demos, stared in awe at the technical feat and then jumped into the code to see how bits are done. Some people’s reactions to these kind of demos are somewhat overblown, saying their pointless and not practical. Very true, but that’s not the point. They’re meant to be inspirational. Showcasing what the technology can do. And to most designers & developers, this is pretty obvious…
But on to the post’s title subject. I found this yesterday, and was blown away by the sheer creativity and ambitiousness. Simon from Simurai.com has done an awesome job re-creating a photography technique known as Tilt Shift using text, text-shadows and rotation. It could be used practically, but it’s best to see it as a creative and inspiring technology demo for now.
We need things like this to keep us excited about a technology. Without these sorts of demos, the majorty would just see CSS3 as text and box shadows… Surely that’s enough reason for the top of the webdesign curve to keep creating things like this and this?
Dublin + Data
Mark Steadman and I took a trip to Dublin for a couple of days in the last week of July thanks to some work we are doing with Birmingham City University. The purpose of this visit was to discover more about an interesting data visualisation application that is nearing completion, and to potentially partner up to apply this application to some of our projects.
The application lets you see what really matters by presenting your data in a fast, dynamic and intuitive visual interface. You can rapidly identify key patterns, trends and expectations, and drilldown to the detail required for effective decision making.
We were given an impressive demo that used large amounts of e marketing data as a case study. It was incredible to see how easily these huge sets of data could be explored in a manageable and visually engaging format.
The project team were really great hosts and took us on a tour of a few Dublin hotspots in the evening, so needless to say we managed to enjoy a bit of Guinness.
We are now working closely with the team in Dublin to produce various case study demos using interesting data from several of our projects. If you could benefit by exploring your data in a refreshing way then please get in touch with us to discuss the potential.
Back to basics – Templates from scratch
Last week I got the chance to be involved in a new and really exciting Substrakt project. After seeing some awesome designs by Ryan I started to write some template code. This will later be used by our developers to implement some very tidy tech wizardry.
The process of translating a design into code is the norm to me as I spend most of my working day realising the brilliant work that our design team does, but much of my work is in WordPress, which means building on existing themes and frameworks. It really felt great to be able to build flat HTML templates from scratch on this new project, and I’m really enjoying writing each and every line of code myself.
Being a fan of super clean and elegant code (I’m somewhat obsessive over indentation and the general condition of code; if someone else cant jump onto one of my projects and find their way around the code easily, its not good enough), it is refreshing to have total control from the start and write everything in my own style. It has also been nice to work with the 960 grid during this project. On WordPress jobs I use a Substrakt modified version of the Blueprint grid system called Redprint, but am now considering refactoring our default WordPress theme to use the 960 Grid.
Hopefully we’ll get more chances to work on completely bespoke projects so that we can write more really awesome code from scratch, because I love it!



