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.

[pastacode lang=”php” manual=”%2F**%0A%20*%20Register%20the%20module%20and%20its%20form%20settings.%0A%20*%2F%0AFLBuilder%3A%3Aregister_module(‘UniqueModulePrefixModule’%2C%0A%20%20%09array(%0A%09%20%20%09’general’%20%20%20%20%20%20%20%3D%3E%20array(%0A%09%20%20%09%09’title’%20%20%20%20%20%20%20%20%20%3D%3E%20__(‘General’%2C%20’textdomain’)%2C%0A%09%20%20%09%09’sections’%20%20%20%20%20%20%3D%3E%20array(%0A%09%20%20%09%09%09’sectionname’%20%3D%3E%20array(%0A%09%20%20%09%09%09%09’title’%20%20%20%20%20%20%20%20%20%3D%3E%20__(%20’Field%20Title’%20%2C%20’textdomain’%20)%2C%0A%09%20%20%09%09%09%09’fields’%20%20%20%20%20%20%20%20%3D%3E%20array%20(%0A%09%20%09%09%09%09%09’my_text_field’%20%20%20%09%3D%3E%20array(%0A%09%09%09%09%09%09%20%20%20%20’type’%20%20%20%20%20%20%20%20%20%20%3D%3E%20’text’%2C%0A%09%09%09%09%09%09%20%20%20%20’label’%20%20%20%20%20%20%20%20%20%3D%3E%20__(‘field%20label’%2C%20’textdomain’)%2C%0A%09%09%09%09%09%09%09’default’%20%20%20%20%20%20%20%3D%3E%20’20’%2C%0A%09%09%09%09%09%09%09’maxlength’%20%20%20%20%20%3D%3E%20’3’%2C%0A%09%09%09%09%09%09%09’size’%20%20%20%20%20%20%20%20%20%20%3D%3E%20’4’%2C%0A%09%09%09%09%09%09%09’description’%20%20%20%3D%3E%20’px’%2C%0A%09%20%20%09%09%09%09%09)%2C%0A%09%20%20%09%09%09%09)%2C%0A%09%20%20%09%09%09)%2C%0A%09%20%20%09%09)%2C%0A%09%20%20%09)%2C%0A%09)%0A)%3B%0A%0A%2F%2F%20%20use%20%24settings-%3Emy_text_field%20to%20retreive%20set%20value%20in%20frontend.php%2C%20frontend.js.php%2C%20frontend.css.php%0A%0Aecho%20%20%24settings-%3Emy_text_field%3B” message=”” highlight=”” provider=”manual”/]

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

[pastacode lang=”php” manual=”%2F**%0A%20*%20Register%20the%20module%20and%20its%20form%20settings.%0A%20*%2F%0AFLBuilder%3A%3Aregister_module(‘UniqueModulePrefixModule’%2C%0A%20%20%09array(%0A%09%20%20%09’general’%20%20%20%20%20%20%20%3D%3E%20array(%0A%09%20%20%09%09’title’%20%20%20%20%20%20%20%20%20%3D%3E%20__(‘General’%2C%20’textdomain’)%2C%0A%09%20%20%09%09’sections’%20%20%20%20%20%20%3D%3E%20array(%0A%09%20%20%09%09%09’sectionname’%20%3D%3E%20array(%0A%09%20%20%09%09%09%09’title’%20%20%20%20%20%20%20%20%20%3D%3E%20__(%20’Field%20Title’%20%2C%20’textdomain’%20)%2C%0A%09%20%20%09%09%09%09’fields’%20%20%20%20%20%20%20%20%3D%3E%20array%20(%0A%09%20%20%09%09%09%09%09’my_photo_field’%20%3D%3E%20array(%0A%09%20%20%09%09%09%09%09%20%20%20%20’type’%20%20%20%20%20%20%20%20%20%20%3D%3E%20’photo’%2C%0A%09%20%20%09%09%09%09%09%20%20%20%20’label’%20%20%20%20%20%20%20%20%20%3D%3E%20__(‘Photo%20Field’%2C%20’textdomain’)%2C%0A%09%20%20%09%09%09%09%09%20%20%20%20’show_remove’%09%3D%3E%20false%2C%0A%09%20%20%09%09%09%09%09)%2C%0A%09%20%20%09%09%09%09)%2C%0A%09%20%20%09%09%09)%2C%0A%09%20%20%09%09)%2C%0A%09%20%20%09)%2C%0A%09)%0A)%3B%0A%0A%2F%2F%20%20use%20%24settings-%3Emy_photo_field%20and%20%24settings-%3Emy_photo_field_src%20to%20retreive%20set%20value%20in%20frontend.php%2C%20frontend.js.php%2C%20frontend.css.php%0A%0A%24attachmentID%20%3D%20%20%24settings-%3Emy_photo_field%3B%0A%0Aprintf%20(%20%20%20’%3Cimg%20src%3D%22%25s%22%20border%3D%220%22%3E’%2C%20%24settings-%3Emy_photo_field_src%20)%3B” message=”” highlight=”” provider=”manual”/]

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.