Skip Navigation

[Closed] Custom Image Field – Show Alt and Title Text

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 11 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

Tagged: 

This topic contains 11 replies, has 3 voices.

Last updated by Caridad 11 years, 9 months ago.

Assisted by: Caridad.

Author
Posts
#10991

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?

#10993

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

#10996

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!

#10997

Also, I don't have the "Views" plugin, so that could be the reason why the "wpv-post_title" shortcode isn't rendering.

#10998

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

#10999

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

#11000

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.

#11001

So how would I pull the image title and alt text that is already saved?

#11003

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']));
#15269

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.

#15270

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.

#15275

This topic is closed.

The topic ‘[Closed] Custom Image Field – Show Alt and Title Text’ is closed to new replies.