On using the Custom Image field, I'm able to upload an image, and I can set the alt and title text in the media upload window. Then I assign it to the custom field. On the front end, I want to display the image with the alt and title tags, but I'm not sure how to do this. Looking at the Views API, I see where I can statically set the alt and title text for the image, however, in my case I am placing a random post (with it's custom image) on the page and therefore need a way to dynamically pull the alt and title text. Does anyone know how to do this?
Dear Klongpayabal,
You can nest shortcode sometimes, like this:
[types field="logo" alt="[wpv-post-title]" title="[wpv-post-title]"][/types]
Please let me know if there is anything else that I can assist you with.
Regards.
Caridad
I tried using that, but then the alt and title tags end up being just the full url of the image, and not the alt and title text. Since I'm adding this to my template php page, I am using the "do_shortcode()" function. the code I have is:
echo do_shortcode('[types field="mdis_tip" alt="[wpv-post-title]" title="[wpv-post-title]"][/types]');
Am i missing something? Thanks for your response!
Also, I don't have the "Views" plugin, so that could be the reason why the "wpv-post_title" shortcode isn't rendering.
Dear Klongpayabal,
In my tests that code worked, but it really depends on the context.
Could you send me the template file to take a look?
Regards,
Caridad
Dear Klongpayabal,
Yes, you are right, you can ignore my last post. You can always create your own shortcode for doing this.
Please let me know if there is anything else that I can assist you with.
Regards.
Caridad
In order to use the Views Shortcodes (wpv-post-title), do you need to have the Views plugin installed? I only have the Types plugin installed.
So how would I pull the image title and alt text that is already saved?
OK, I've figured it out (at least one way to do it). First, within the loop, you need to get the attachment information for the image:
$args = array(
'numberposts' => 1,
'order'=> 'ASC',
'post_mime_type' => 'image',
'post_parent' => $post->ID,
'post_type' => 'attachment'
);
$get_children_array = get_children($args,ARRAY_A); //returns Array ( [$image_ID]...
$rekeyed_array = array_values($get_children_array);
$child_image = $rekeyed_array[0];
Then you need to use the types_render_field call along with the $child_image['post_title'] to set the title and alt tags:
echo types_render_field("mdis_tip", array("output"=>"html","size"=>"footer-tip", "alt" => $child_image['post_title'], "title" => $child_image['post_title']));
How can I use URL from custom field URL around the image type using TYpes and Views tags?
<a href="[wpcf-mycustomurl]">[types field="logo" alt="[wpv-post-title]" title="[wpv-post-title]"][/types]</a>
does not work.
Yay! Its
<a href=[types field="company_website" raw="true" ][/types]>[types field="company_logo" align="left" title="[wpv-post-title]"][/types]</a>
I should have read docs more carefully.