Skip Navigation

[Resolved] Toolset gallery slider displaying duplicates when not enough values

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to use a slider for an image repeating field. The slider duplicates images when there is a low number than the items of the slider. The user would like to disable this duplication.

Solution:
We cannot disable the duplication of images on the slider, this is expected behavior that ensures the sliding effect of images.

On the other hand, we can implement a custom function that counts the number of items on the images field and display different block for each count (1, 2, 3, >=4)

function count_repeat_field($post_id, $field) {
    return sizeof(get_post_meta( $post_id, 'wpcf-' . $field, false ));
}

Relevant Documentation:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-custom-functions-in-conditions/

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by RensV5812 4 years, 8 months ago.

Assisted by: Jamal.

Author
Posts
#1582129
Screenshot 2020-04-11 at 12.36.21.png
Screenshot 2020-04-11 at 12.36.21.png

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

#1582287

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.

#1584743

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

#1585123

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.

#1585199

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