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
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
Hello Jamal
When i try toi acces to hidden link
i get this message
You have no access to this specific snippet
Guy
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.
Hi Jalmal
I tried with this function (with my fields slug), but it breaks the functions.php file.
do you now why
Guy
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. **
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.
My issue is resolved now. Thank you!