Skip Navigation

[Resolved] slider with one image

This support ticket is created 3 years, 10 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 7 replies, has 2 voices.

Last updated by kayser 3 years, 10 months ago.

Assisted by: Jamal.

Author
Posts
#1959721

hidden link
Hello
In this slider there is only one image and it is repeated 3 times in the thumbnail bar.
How to display only the image, this is an exception in the set of book sliders. I didn't manage to produce the shortcode with if
Can you help me
Thank you

#1960227

Hello and thank you for contacting the Toolset support.

I assume that you have configured the Slider to have 3 items per page, right?
It will always have 3 items per page. For example, if the post has only two images, the first one will be duplicated as being the 3rd.

If you want to handle the case of fewer than 3 images, I'll suggest that you wrap the slider inside a conditional block that will check the count of images. If you have only one image, display an Image block instead of the slider. If you have 2 images display a Slider with 2 items. And if you have 3 or more images display the current Slider.

There is no built-in way to count the number of images, so you will have to add custom code for it. You can create a function and register it to be used in conditionals in Toolset Settings. Check this article https://toolset.com/documentation/programmer-reference/views/using-custom-functions-in-conditions/

You can get inspired by this custom shortcode hidden link

#1960243

Hello Jamal
When i try toi acces to hidden link
i get this message
You have no access to this specific snippet
Guy

#1960305

Hello Guy, that's not expected, I'll check with our system team. The snippets website should be available to any visitor.

In the meantime, you can find the shortcode's code here https://toolset.com/forums/topic/how-to-count-repeated-field/#post-412707

The function should be basically:

function my_count_repeatable field() {
  global $post;
  $field_slug = 'book_images';
  return sizeof(get_post_meta( $post->ID, 'wpcf-' . $field_slug, false ));
}

Adapt line 3 to your field's slug.

#1962943

Hi Jalmal
I tried with this function (with my fields slug), but it breaks the functions.php file.
do you now why
Guy

#1962959

Would you allow me temporary access to check this further? I will also need FTP access to recover the functions.php file if the code breaks the site. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1964083

I did not spot the issue with the code yesterday. The code has a mistake. The function name should be "my_count_repeatable_field" with an underscore before "field" instead of "my_count_repeatable field". Final code after adapting the field slug below:

function my_count_repeatable_field() {
  global $post;
  $field_slug = 'livre-images';
  return sizeof(get_post_meta( $post->ID, 'wpcf-' . $field_slug, false ));
}

I added the code to Toolset->Settings->Custom code and registered the function in Toolset Settings. Then I built three conditional blocks with the function:
- When there is only one image. I put an Image block inside of it.
- When there are two images. I put a new slider with two thumbnails inside of it.
- When there 3 or more images. I moved the existing slider into it.

The existing slider is displayed for this post that has 4 images hidden link
The Image block is displayed for this post, that did not have an image, and where I added the featured image in the custom field too hidden link

I'll let you check for a post that has only 2 images in the field, it should display a slider with two thumbnails similar to this preview hidden link

I'll remain at your disposal.

#1964091

My issue is resolved now. Thank you!