Skip Navigation

[Resolved] Add code for image caption in theme template

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 9 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.

This topic contains 5 replies, has 2 voices.

Last updated by Ghennadi 9 years, 11 months ago.

Assisted by: Ghennadi.

Author
Posts
#213074
caption.JPG

Hi, I want to show the caption of an image. I made a repeated field for images. This is the code in my single.php:
<?php echo types_render_field("foto", array("width"=>"306","resize"=>"crop","height"=>"226","align"=>"left","title"=>"")); ?>

How can I do this? (Look at the image in the attachment.)

#213145

Dear Dido,

Can you try this:

<?php echo img_caption_shortcode(array(), types_render_field("foto", array("width"=>"306","resize"=>"crop","height"=>"226","align"=>"left","title"=>""))); ?>

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.

#213147

Unfortunatelly not working. I see now 1 image (not the following 2) without the text.

#213152

Dear Dido,

Sorry i forgot that it's repetitive.
Please try this:

$myvar = '[caption]'.types_render_field("foto", array("width"=>"306","resize"=>"crop","height"=>"226","align"=>"left","title"=>"", "separator"=>'[/caption][caption]')).'[/caption]';
echo do_shortcode($myvar);

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.

#213153
code.JPG
caption-2.JPG

Hi Ghennadi, Still not working good. See my screenshots.

#213334

Dear Dido,

Hi, this code will work.

$myvar = explode( ',', types_render_field("foto", 
					array("width"=>"306","resize"=>"crop","height"=>"226","align"=>"left","title"=>"", 
					"separator"=>',')));
					if ( count($myvar) >0 ){
						$images = '';
						for ($i=0,$l=count($myvar);$i<$l;$i++){
							$images .= '[caption]'.$myvar[$i].'[/caption]';
						}
						echo do_shortcode($images);
						
					}

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.