Show just first image with WP Types

If you are using WordPress Types plugin for Custom Fields and Custom Post Types Management and you use image custom filed, sometimes you may need to show just one image instead of all uploaded for particular post or page.
I am not using shortcodes but PHP implementing, so some situations and needings can be tricky. For instance, I didn’t found solution for this one, how to show just one image when you uploaded several of them in one post. In fact I did found this:

$custom_image = types_render_field("custom-image", array("raw"=>"html","separator"=>" ","alt"=>"","title"=>"","index"=>"1"));
echo "".$custom_image;

where that “index”=>”1” part should show just one image, and yes, it does that, but it shows second uploaded image, not first one. So when you uploaded just one image that code won’t show anything. In that case, just replace that 1 to 0

"index"=>"0"

and your first uploaded image will be showed. If you need just second one, of course leave 1, or write 2 if you need 3rd image presented.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

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