• Resolved bookit

    (@bookit)


    Hi David,

    Thank you for a great plugin!

    You’ve assisted me earlier with a PHP code to show sliders in an archive based on images from ACF. This works fine with most of our posts as we have many images in our posts. However, we have one post with only 3 images, and for some reason the slider only shows 2 images when loaded. The 3rd is visible after sliding, but it only shows 2 images at the time (for other posts it shows 3-4 images at the same time based on screen width).

    Do you have any idea why this would happen? It shows all 3 images if I set center_selected_slide=”true” , but I need this to be false to avoid post with 3 images to be centered.

    Below is the code you helped with earlier:

    $postid = get_the_ID();
    $postlink = get_permalink();
    echo ‘

    ‘;
    // If at least 1 image is present in the Project Images Gallery field
    if( $images = get_field(‘bilder’) ) {
    $image_ids = wp_list_pluck( $images, ‘url’ );
    //$resizedImage = fImg::resize( ‘. $resizedImage . ‘, 600, 400, false ); // width, height, false = maintain aspect ration, true = crop
    // Use thumbnails, only if we have more than 1 image
    $use_thumbnails = ( 1 < count( $image_ids ) ? true : false ); // Show slider echo ‘

    ‘;
    $slider = ‘

    [sliderpro id=”‘ . $postid . ‘” width=”600″ height=”400″ visible_size=”2600″ arrows=”true” autoPlay=”false” auto_thumbnail_images=”‘ . $use_thumbnails . ‘” lazy_loading=”true” loop=”true” center_selected_slide=”false” allow_cache=”true”]’;

    foreach($image_ids as $image_id) {
    $slider .= ‘[sliderpro_slide] [sliderpro_slide_element name=”main_image_source”]’ . $image_id . ‘[/sliderpro_slide_element][sliderpro_slide_element name=”main_image_link”]’ . $postlink. ‘[/sliderpro_slide_element][/sliderpro_slide]’;
    }

    $slider .= ‘[/sliderpro]

    ‘;

    echo do_shortcode($slider);

    echo ”;
    }


    Thank you,
    Lars

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author bqworks

    (@bqworks)

    Hi Lars,

    You could try disabling lazy_loading for sliders that contain less than 3 images. Something like this:

    $use_lazy_loading = count( $image_ids ) > 3 ? true : false;
    ...
    [sliderpro id="' . $postid . '" ... lazy_loading="' . $use_lazy_loading . '" ];

    Best,
    David

    Thread Starter bookit

    (@bookit)

    Hi David,

    Thank you for your reply. As a test, I changed lazy_loading to false for all sliders (and cleared cache etc), but it was still same problem with this slider that only contains 3 images.

    So I don’t understand what’s causing this problem. Is the last image in a slider always hidden somehow?

    Thank you
    Lars

    Plugin Author bqworks

    (@bqworks)

    Hi, Lars. Can you share a link to the page?

    Best,
    David

    Thread Starter bookit

    (@bookit)

    Hi David,

    I’ve temporarily the page available here:
    https://www.staging5.innovabygg.no/nybygg/

    The error you see “Warning: Undefined array key “name” in” above each slider seems to only appear when I’ve set allow_cache=”false” (this is temporarily set to false due to the testing, but maybe you know what’s wrong here as well?)

    Thank you
    Lars

    • This reply was modified 1 year, 7 months ago by bookit.
    Plugin Author bqworks

    (@bqworks)

    Hi Lars,

    The problem with the three slides is that, when you have the loop option enabled, there is a centered slide and the other slides are arranged before and after the centered slide, so the third slide is actually visible but positioned before the first slide. If you drag the slide to the right, you will see the third slide before the first one. This is for achieving the loop effect. The solution would be to disable loop for this slider, similarly to how I suggested to disable lazy_loading above.

    Regarding the error, it’s caused by not having a “name” defined for this dynamically generated sliders. You can fix it by add a name:

    [sliderpro id="' . $postid . '" name="Slider ' . $postid . '" ... ];

    Best,
    David

    Thread Starter bookit

    (@bookit)

    Hi David.

    Thank you, disabling loop for posts with few images solved that problem ??

    For the name, I’ve updated my code and using the following – but I still get the same error:

    // Show slider
    echo ‘

    ‘;
    $slider = ‘[sliderpro id=”‘ . $postid . ‘” name=”Slider ‘ . $postid . ‘” width=”600″ height=”400″ visible_size=”2600″ arrows=”true” autoPlay=”false” auto_thumbnail_images=”‘ . $use_thumbnails . ‘” lazy_loading=”true” loop=”‘ . $use_loop . ‘” center_selected_slide=”false” allow_cache=”false”]’;

    foreach($image_ids as $image_id) {
    $slider .= ‘[sliderpro_slide] [sliderpro_slide_element name=”main_image_source”]’ . $image_id . ‘[/sliderpro_slide_element][sliderpro_slide_element name=”slider”]’ . $postlink. ‘[/sliderpro_slide_element][/sliderpro_slide]’;
    }

    I don’t get any error if I change allow_cache to true,

    Thanks
    Lars

    Plugin Author bqworks

    (@bqworks)

    Hi Lars,

    I can’t see the error anymore.

    Best,
    David

    Thread Starter bookit

    (@bookit)

    Hi David,

    Sorry, it’s because I forgot to change allow_cache back to false.
    Please try again now,

    Thanks
    Lars

    Plugin Author bqworks

    (@bqworks)

    Hi Lars,

    I will take a closer look next week and get back to you.

    Best,
    David

    Thread Starter bookit

    (@bookit)

    Thank you David,

    Please note that we will use allow_cache = true on live site, so I think we can close this issue unless you think this is something we should solve,

    Thanks
    Lars

    Thread Starter bookit

    (@bookit)

    Marking this as solved

    Plugin Author bqworks

    (@bqworks)

    Hi, Lars. Sorry for the delay. I’ve found that it was a bug in the plugin occurring only when using shortcode generated sliders. The fix is easy, but I won’t release the update yet. If you want to, you can add the following line in wp-content/plugins/sliderpro/public/class-sliderpro.php, after line 566:

    $slider['name'] = isset( $atts['name'] ) ? $atts['name'] : '';

    Best,
    David

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Problem with slider if it only contains few images’ is closed to new replies.