• Resolved charlie67p

    (@charlie67p)


    Hi,

    I created a CPT ”event”.

    On the bottom of the single event template, there is a carousel querying all the events ordered by date ascending (each carousel-item shows the title, the featured image, and the event’s date) = I use the CBB carousel like a menu to navigate quickly from an event to the other.

    Would it be possible to dynamically center the carousel on the current event’s carousel-item (to see quickly which event comes earlier, and which event comes later) ?
    [ I think it’s not possible for now, but might be an interesting feature…]

    Thanks

    • This topic was modified 1 month, 2 weeks ago by charlie67p.
    • This topic was modified 1 month, 2 weeks ago by charlie67p.
    • This topic was modified 1 month, 2 weeks ago by charlie67p.
    • This topic was modified 1 month, 2 weeks ago by charlie67p.
Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Phi Phan

    (@mr2p)

    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.

    Thread Starter charlie67p

    (@charlie67p)

    thank you @mr2p

    Plugin Author Phi Phan

    (@mr2p)

    @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.

    Thread Starter charlie67p

    (@charlie67p)

    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.

    Plugin Author Phi Phan

    (@mr2p)

    @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.

    Thread Starter charlie67p

    (@charlie67p)

    How to debug the post IDs ?

    Plugin Author Phi Phan

    (@mr2p)

    @charlie67p You can simply use error_log to log $posts, $current_id, and $carousel_settings from the snippet above.

    Thread Starter charlie67p

    (@charlie67p)

    Sorry but I don’t know where to find error_log and how to log $posts$current_id, and $carousel_settings

    Thread Starter charlie67p

    (@charlie67p)

    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.
    Plugin Author Phi Phan

    (@mr2p)

    @charlie67p That might be the issue. When slidesPerGroup is greater than 1, it can affect how initialSlide behaves.

    Thread Starter charlie67p

    (@charlie67p)

    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 !

    Plugin Author Phi Phan

    (@mr2p)

    @charlie67p Thanks for the update, and you’re very welcome!

Viewing 12 replies - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.