I’m making a custom page template in wordpress and adding an image by using a custom field. Like this:
<img src="<?php echo bloginfo('url') ?><?php echo get_post_meta($post->ID, 'main_picture', true); ?>" />
I’m putting the path to the image in a custom field.
The image is uploaded through the custom panel so the custom files will have a Name of ‘main_picture’ and a value of the upload path, like so – ‘wordpress/wp-content/uploads/2012/01/mypic.png’
I’d prefer to be able to reference the image by title, and extrapolate the image url from that title.
Is that possible?
Let me know if my question doesn’t make sense. I’m quite new to wordpress.
———————-edit———-
I realise that using the image name is not a great idea, as it won’t always be unique. I;m trying to make it as easy on the client as possible. They’re going to be wary of using custom fields, image names will be the easiest thing for them to understand.
I’d suggest ditching custom fields entirely then and creating your own metabox interface for uploading images and naming them etc. The answer to your question from unknown_guy is a good start. Custom fields are a crap user experience imho.
And are you talking about getting the client to insert the image into the post content? If so, combine a metabox ui with a shortcode interface. Something that when the client has filled in the required fields for image, name etc, gives them some code to ‘paste’ or insert where they want it to show up.
Metabox tutorials:
http://www.farinspace.com/how-to-create-custom-wordpress-meta-box/
http://wp.tutsplus.com/tutorials/plugins/how-to-create-custom-wordpress-writemeta-boxes/
http://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html
Maybe you should try doing this with plugin. I suggest Advanced Custom Fields