If you're building WordPress up as CMS you'll quickly find yourself needing the ability to add custom fields to custom templates. You can of course do this by default in the admin panel, but each time you create a new page you need to manually type in all the custom field types - not great for your end-users. What would be better is if all the custom fields associated with a specifc template show as options when the template is selected.
Here's how you can do it...
To achieve our goal we'll be installing a plugin called 'Advanced Custom Fields'. The plugin allows you to do a lot more with custom fields than just assign them to page templates, but this is what we'll be focussing on in this post.
Install the 'Advanced Custom Fields' plugin found here: http://wordpress.org/plugins/advanced-custom-fields/installation/
or by searching in the plugins section for 'advanced custom fields' under 'Add new'. After installation click to 'Activate' the plugin. You'll now see that 'Custom fields' has been added to the bottom of your admin menu.
In a previous blog article we looked at how to create custom page templates. We're now going to assign some custom fields to a template described in that article.
If you go to one of your pages now and select your custom template, you'll notice that the additional custom fields are available.
You can access your new fields using the following snippet ('about' being our new custom field):
The 'get_post_meta' takes three arguments; the id of the post / page, the key for the custom field name and if you are expecting an array of results or a single result.