[Support request] Adjusting results for display and autoplay in carousel

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Adjusting results for display and autoplay in carousel

  • This topic has 6 replies, 3 voices, and was last updated 3 months ago by P.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #23100
    P
    Participant

    Dear team,

    I would appreciate your support with the following questions. I can split them in different posts, if you prefer to.

    1) I have a list of posts to be displayed in a carousel, ordered from most recent to oldest. I would like to skip the most recent and start the list with the 2nd most recent. Is it possible?

    2) I have another list that presents posts of a certain category as cards (Base layout, 3 cols, title + 30 word excerpt). I marked the option “Featured post”. I would like to display a longer excerpt (eg 50 words) for the featured post only, since it has a bigger box. Is it possible?

    3) Can the autoplay for a carousel be enable/disabled somewhere in the settings?

    Feel free to direct me to previous posts, if relevant. I could not find anything.
    Thank you in advance for your great support so far, by Elvin (i’m assuming he’s part of your support team).
    Best regards,
    Paulo

    #23144
    elvin
    Moderator

    Hi,

    1) I have a list of posts to be displayed in a carousel, ordered from most recent to oldest. I would like to skip the most recent and start the list with the 2nd most recent. Is it possible?

    WPSP uses Slick library – https://kenwheeler.github.io/slick/

    And we can control how the settings using wpsp_carousel_args filter.

    Example:

    add_filter( 'wpsp_carousel_args', function( $args ) {
        $args['initialSlide'] = 1;
        return $args;
    } );

    It starts at 0. So basically, 1st post = 0, 2nd post = 1, 3rd post = 2 and so on.

    2) I have another list that presents posts of a certain category as cards (Base layout, 3 cols, title + 30 word excerpt). I marked the option “Featured post”. I would like to display a longer excerpt (eg 50 words) for the featured post only, since it has a bigger box. Is it possible?

    Not sure if this will work but try this: (change 123 to your WPSP list id)

    add_filter( 'excerpt_length', function( $featr ) {
        if ( 123 === (int) $settings['list_id'] && $settings['featured_post'] ); ) {
            global $wp_query;
    
            if ( 0 === $wp_query->current_post ) {
                return 10; // Whatever the length you need for the first post.
            }
        }
    
        return $length;
    }, 999 );

    3) Can the autoplay for a carousel be enable/disabled somewhere in the settings?

    In relation to question #1, you can add in $args['autoplay'] = true;

    Example:

    add_filter( 'wpsp_carousel_args', function( $args ) {
        $args['autoplay'] = true;
        $args['initialSlide'] = 1;
        return $args;
    } );
    #23437
    P
    Participant

    Hi Elvin,

    Thank you once again for the replies. I would be thankful if i could have your help still, since there are a couple of issues.

    Regarding questions #1 and #3: it works, but when i apply it but it makes the carousel only show one item/post “per slide”, instead of the 3 per slide that i had defined in the properties of the list. I added an if clause to apply it only to a specific carousel; the problem happens with or without the if clause:
    add_filter( ‘wpsp_carousel_args’, function( $args ) {
    if ( 1477 === $settings[‘list_id’] ) {
    $args[‘autoplay’] = false;
    return $args;
    }
    } );

    Regarding #2, there seem to be 2 problems with the code you suggested:
    – On the one hand, it does not change the length of the excerpt, at all. I replaced the “123” for the list_id and tried different values for the “return” value. No visible effect.
    – On the other hand, it does not see to correctly restrict (match?) the first if condition just to the featured post. I replaced the “global $wp_query” expression with a simple echo “message”, to see if and where it would show up. Result: all the posts in the list showed that message between title and excerpt, not just the featured one. I’ve tried to dig into the plugin code to see how it is marked, but it goes past my know-how to find a solution 🙁

    Any idea on how to proceed? I’ve tried to combine your suggestion with the function suggested in WordPress’s Code reference, but no luck either:

    function mytheme_custom_excerpt_length( $length ) {
    if ( 1496 === (int) $settings[‘list_id’] && $settings[‘featured_post’] ); {
    global $wp_query;

    if ( 0 === $wp_query->current_post ) {
    return 10; // Whatever the length you need for the first post.
    }
    }

    return $length;
    }
    add_filter( ‘excerpt_length’, ‘mytheme_custom_excerpt_length’, 999 );

    Thank you in advance and best regards,
    Paulo

    #23536
    Tom
    Keymaster

    Hi there,

    Instead of this $args['initialSlide'] = 1;, try setting the “Offset” option in the “More Settings” panel in your list to 1. This should tell the list to skip the first post.

    As for the excerpt length, try this:

    add_filter( 'excerpt_length', function( $featr ) {
        if ( 123 === (int) $settings['list_id'] && $settings['featured_post'] ) {
            global $wp_query;
    
            if ( 0 === $wp_query->current_post ) {
                return 10; // Whatever the length you need for the first post.
            }
        }
    
        return $length;
    }, 1000 );
    #23623
    P
    Participant

    Dear Tom,

    Thank you for the follow-up and suggestion.
    The first question is solved, but the excerpt length one unfortunately not.

    I’ve tried the suggested code but it changes the excerpt length for all the posts in the list, not just the featured post (as desired). Upping the priority to 1000 did not make a difference. I had also replaced the ); ) { with ); { by at the end of line two as it threw a validation error.

    For now, i simply added a manual excerpt to the featured post, but it would be preferable to have the automatic behaviour in place, if possible.

    Would it help if i give you access to the dev site?

    I really appreciate your continued support! Best,
    Paulo

    #23664
    Tom
    Keymaster

    Ah, I see the issue – the $settings variable isn’t available in that filter.

    This would be possible to apply to ALL post lists (including theme archives) on your site, but it won’t be possible to apply to a specific list.

    #23667
    P
    Participant

    Thank you once again. I’m not quite sure i get the full implication of your answer but i get the gist of it 🙂

    Since having the conditions inside the add_filter does not work, would it help to define the function custom_excerpt_length before calling the add_filter?

    In the function, we could define the custom excerpt length if the post is in a given WPSP list and if it’s the latest published one (as in “if ( 0 === $wp_query->current_post )”); otherwise, the normal excerpt would be applied. I’ve tried fiddling with the code but this is above my know-how.

    It could be a question for stack exchange but i’m not sure how much the solution is dependent on any given specificity of WPSP (ie interaction with the different WP classes, etc).

    Thanks in advance,
    Paulo

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.