Hi Charlie @charlie67p,
Thanks for your feedback and suggestion. You’re right, the current version of CBB does not support this feature yet.
In the next version, I’ll add a filter that allows users modify carousel settings on the server. That will handle your use case cleanly.
Here is the custom code for your use case. It will work in the next version:
add_filter( 'cbb_get_carousel_settings', function( $carousel_settings, $parsed_block, $block ) {
if ( ! is_singular( 'event' ) ) {
return $carousel_settings;
}
if ( $block && isset( $block->context['query'] ) ) {
$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
$page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
$query_args = build_query_vars_from_query_block( $block, $page );
$query_args['fields'] = 'ids';
$current_id = get_the_ID();
$posts = get_posts( $query_args );
if ( $current_id && in_array( $current_id, $posts, true ) ) {
$carousel_settings['initialSlide'] = array_search( $current_id, $posts, true);
}
}
return $carousel_settings;
}, 10, 3 );
Best, Phi.
@charlie67p I’ve just released version 2.8.10. The snippet above should work now. Don’t forget to enable Active slide at the center in the UI.
Best, Phi.
Hi @mr2p,
Thank you very much,
but not working correctly for me,
sometimes the current Event is at the center, sometimes it is not…
( I tried with the 3 loop modes None/Rewind/Infinite )
Could it be a problem of cache ?
… I don’t have the time to do more tests right now
>> I’ll be back here as soon as I can tell a bit more about it.
@charlie67p I think infinite mode may be affecting the result. You might want to set the loop mode to none or rewind instead.
You can also debug the post IDs and the carousel settings value to see what might be causing the issue.
Please let me know how it goes.
How to debug the post IDs ?
@charlie67p You can simply use error_log to log $posts, $current_id, and $carousel_settings from the snippet above.
Sorry but I don’t know where to find error_log and how to log $posts, $current_id, and $carousel_settings
Ah, I just tried with slides per group : 1 and it’s working
Not working with slides per group 2, nor 3
-
This reply was modified 1 month ago by
charlie67p.
@charlie67p That might be the issue. When slidesPerGroup is greater than 1, it can affect how initialSlide behaves.
Hi @mr2p , yes , it’s working perfectly with slidesPerGroup : 1 and I’ll keep it like this.
Thank you very much for this new feature !
@charlie67p Thanks for the update, and you’re very welcome!