Getting the set Photo thumb-image

I’ve been bashing my head over this the other day. I was constructing the Owl-slider module and needed the thumb-image that I had set using the photo-field. Now, after finding out the solution it appears it is clearly mentioned in the documentation but never the less I’m going to repeat it here so that you don’t have to go through this like me.

Almost all default fields return a value set by there own variable name. So when you set a text-field with the name my_text_field, you can use it with the $settings->my_text_field variable.

/**
 * Register the module and its form settings.
 */
FLBuilder::register_module('UniqueModulePrefixModule',
  	array(
	  	'general'       => array(
	  		'title'         => __('General', 'textdomain'),
	  		'sections'      => array(
	  			'sectionname' => array(
	  				'title'         => __( 'Field Title' , 'textdomain' ),
	  				'fields'        => array (
	 					'my_text_field'   	=> array(
						    'type'          => 'text',
						    'label'         => __('field label', 'textdomain'),
							'default'       => '20',
							'maxlength'     => '3',
							'size'          => '4',
							'description'   => 'px',
	  					),
	  				),
	  			),
	  		),
	  	),
	)
);

//  use $settings->my_text_field to retreive set value in frontend.php, frontend.js.php, frontend.css.php

echo  $settings->my_text_field;

Using a photo-field however will leave you with TWO usable variables:

/**
 * Register the module and its form settings.
 */
FLBuilder::register_module('UniqueModulePrefixModule',
  	array(
	  	'general'       => array(
	  		'title'         => __('General', 'textdomain'),
	  		'sections'      => array(
	  			'sectionname' => array(
	  				'title'         => __( 'Field Title' , 'textdomain' ),
	  				'fields'        => array (
	  					'my_photo_field' => array(
	  					    'type'          => 'photo',
	  					    'label'         => __('Photo Field', 'textdomain'),
	  					    'show_remove'	=> false,
	  					),
	  				),
	  			),
	  		),
	  	),
	)
);

//  use $settings->my_photo_field and $settings->my_photo_field_src to retreive set value in frontend.php, frontend.js.php, frontend.css.php

$attachmentID =  $settings->my_photo_field;

printf (   '<img src="%s" border="0">', $settings->my_photo_field_src );

There will be a $settings->my_photo_field and a $settings->my_photo_field_src. The difference is that first value contains the ID of the attachment, so you can use it in any way you seem fit. The second variable is the location of the image and selected thumb-size that you set during the frontend module-settings.

Posted in ,

Beaverplugins

Web ninja with PHP/CSS/JS and Wordpress skills. Also stand-in server administrator, father of four kids and husband to a beautiful wife. Always spends too much time figuring out ways to do simple things even quicker. So that you can benefit.

Leave a Comment