Home›Types Community Support›[Resolved] Need to echo an image path for flexslider data-thumbs using the Types PHP API.
[Resolved] Need to echo an image path for flexslider data-thumbs using the Types PHP API.
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, 5 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.
Dynamically implement Flexslider with Thumbnails (hidden link) using the WP Types PHP API. While I am able to echo the image path, I am not able to inlcude the path for data-thumbs. This is my code in functions.php:
Looks like you want to extract just file names from the complete path. I will suggest to use PHP's pathinfo() function with your code to extract the file names only. The sample code is as below:
Is your case study image a repeating field? Means does all images belong to single post with repeating casestudyimage custom field? Or these images are gathered from more than one posts (casestudyimage custom field having single value or non repeatable)?
Please let me know, so I can offer you more accurate solution.
// Get all values of repeating fields, separated by a comma
// Since the same field is used for thumbs and images, it's enough to fetch once only
$case_study_repeating_images = types_render_field("casestudyimage", array("raw"=>"true", "separator"=>","));
// Create an array of all values, exploded by the separating comma
$images = explode(",", $case_study_repeating_images);
if(!empty($case_study_repeating_images)) {
?>
<ul class="slides">
<?php
// Iterate through each array element and get key (index) and value
foreach($images as $key => $value) {
?>
<li data-thumb="<?=$value?>"><img src="<?=$value?>" /></li>
<?php
}
?>
</ul>
<?php
}
Please notice, that you wanted to output a custom repeating attribute as well, so it is necessary to handle multiple instances in a custom way. Please see the line "$images = explode(",", $case_study_repeating_images);" which addresses this issue, and converts all values in an array based on the separator. So you can iterate through all values.
Also notice, since you were using the same field for thumbnails and images, I have optimized the code to eliminate unnecessary code calls.