New Landing How can we help? Atelier Swift Slider – Load random slide

Viewing 4 posts - 1 through 4 (of 4 total)
  • Posted in: Atelier
  • #200787
    eternalbeta
    Member
    Post count: 76

    Is there any way to have Swift Slider load a random slide to start with or is it locked to loading by post order? I know Revolution Slider has this option, but I would prefer to use Swift Slider since it is a bit lighter impact on site performance. I believe there is a way for default blog posts to be queried at random, so I was thinking there may be a way with swift slider as well.

    Thanks

    #200837
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Hi

    You might be able to get a plugin that does this for custom post types, we usually use Post Types Order to set the order of the slides, but I’m not sure if it has a random option

    – Kyle

    #201000
    eternalbeta
    Member
    Post count: 76

    I actually managed to figure it out last night after I found that WordPress has core functionality for querying and displaying random posts, something I’ve never needed to do before.

    In /plugins/swift-framework/includes/swift-slider/inc/ss-display.php, I added the ‘orderby’ => ‘rand’ to the code below:

      /* SLIDE QUERY
            ================================================== */
            $slide_count         = intval( $slide_count );
            $ss_args             = array(
                'post_type'             => 'swift-slider',
                'post_status'           => 'publish',
                'swift-slider-category' => $slide_category,
                'orderby'             => 'rand',
                'posts_per_page'        => $slide_count,
            );
            $swift_slider_slides = new WP_Query( $ss_args );
            $slides_count        = $swift_slider_slides->found_posts;
            if ( $slides_count < $slide_count ) {
                $slide_count = $slides_count;
            } else if ( $slide_count === 0 ) {
                $slide_count = $slides_count;
            }

    I’ll just need to make a note to myself about this change for when I update the theme.

    #201002
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Ok great! No problem

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.