I’d like to add a meta box to my posts and page editor that will allow me to upload an image and use it as sort of a SECOND featured image. The idea is that my client will be able to upload an image to this meta box to customize the page/posts header image.
Here is an example of what the final result would be: http://gointrigue.com/locations-and-dates/
As you can see at the top of the page there is a large banner of a dancer. Right now this is hardcoded with CSS. I’d like for this to instead be editable by my client from within the WordPress post/page edit screen on a per page and per post basis.
How do I get started?
The functionality you want may be built from scratch but definitely a custom fields plugin will make your life much easier.
I use Advanced Custom Fields, and it gives amazing results and the possibilities are endless.
I haven’t used this one, but it seems pretty good too.
You can use this plugin http://wordpress.org/extend/plugins/multiple-post-thumbnails/ to add secondary featured image to page/posts header image.
I’m one of the developers that maintains this metabox class. it includes an upload field that you can use.
https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
You will have to add a meta box on the post/page edit pages. See the doc for add_meta_box. There is a detailed example here, along with how to handle/save the entered information. In the
myplugin_inner_custom_box
function, replace the text input with a file upload (and/or more fields if you want to). Handle the$_FILE
array in themyplugin_save_postdata
function.use this “Meta Box Script For WordPress”
http://www.deluxeblogtips.com/meta-box-script-for-wordpress/
There are a number of plugins and scripts that others have referenced. The two I prefer as a developer are Meta Box and the Meta Box Class. Both of these do require that you mess with code to set the fields up, but if you are adding custom meta, you will be messing with code to display it anyway.
Advanced Custom Fields is a nice plugin for smaller needs and does allow the addition of new fields on the fly, but each field ( and sub-field – repeaters ) is added as a unique field and for each field you add, the plugin adds 2 fields to the database ( the second being an identifier assigned by ACF. ) So if you are doing a query on a page to get 10 fields, you will actually be doing 20 database queries ( plus one more by ACF ) which can really add to DB query bloat. Use this one carefully.