I am trying to:
Create a gallery slider with four columns that pulls data from a repeating image field of a CPT.
Link to a page where the issue can be seen:
hidden link
I expected to see:
A slider with four columns that has two columns that display a stored image from this post and two empty columns.
Instead, I got:
A slider with four columns that has four columns where both images are outputted twice.
Not sure if this is a bug or just a setting that controls this, I have been searching but have not been able to find a fix though.
Thanks guys,
Rens
Hello and thank you for contacting the Toolset support.
The Toolset Gallery block creates at least 10 slider items to be able to create the slide animation. If it does not hold 10 images, it duplicates the images until it creates 10 items. It is expected to duplicates images.
I hope this answers your question. I remain at your disposal.
Hi Jamal,
Thanks for the reply. Is there a way of disabling the duplicating of items? I'd love to display my custom galleries using this slider because it looks awesome, but I know my site visitors that add these CPT's through front end forms aren't gonna upload more than a few images most of the time.
Would love to hear if there is any sort of workaround.
Cheers,
Rens
Hello Rends,
I don't think that the duplicating behavior will be disabled for a slider. Maybe you would like to use other display settings.
I would suggest to test the count of the items of the field and display a different block/gallery for cases(=0, =1, =2, =3, >=4). Currently, Toolset does not offer a way to count the items of a repeating field. This will need custom code in your theme's functions.php file.
Add the following code to your functions.php file:
function count_repeat_field($post_id, $field) {
return sizeof(get_post_meta( $post_id, 'wpcf-' . $field, false ));
}
Then add the function to Toolset->Settings->Frontend Content->Functions inside conditional evaluations. Check this article for more info https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-custom-functions-in-conditions/
Then, you can use the function in your conditions and implement something like the following:
- If no item, display a message "No image available".
- If 1 item, use a block with a different "Display settings".
- If 2 item, use a block with a different "Display settings".
- If 3 item, use a block with a different "Display settings".
- If >=4 item, use a block with slider "Display settings".
Check this screenshot for a condition in my local example hidden link
I hope this helps. I remain at your disposal.
Hi Jamal,
That's a great idea actually! I'll implement this. I should be okay from here so I'll mark this thread resolved.
Thanks for your help!
Rens