Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #112285
    webtrader
    Participant

    Is it possible to randomize the slides shown in the featured slider? On our home page, I do not always want the slides to be shown starting with the first slide. Every time someone visits the home page, I would like the order of slides to be randomized, or at least start on a random slides.

    If there is no way to set the slider to randomize via the GUI, is there an easy change somewhere in the code where I can pull the slides and perform a PHP shuffle() on the array of slides to be shown?

    Thank you.

    #112319
    Pratik
    Participant

    Hi @webtrader,

    It is not as easy as using PHP shuffle. There needs to be some customization to the theme and cannot be achieved by GUI (as you have mentioned).

    For that, first create a child theme via tutorial here: http://catchthemes.com/blog/create-child-theme-wordpress/. After that, I will provide you with the codes. Also, please post in your site url.

    Regards,
    Pratik

    #112322
    webtrader
    Participant

    Pratik,

    I have created child theme. Our website is still in development and I would prefer not to post URL on forum. Is it possible to message that to you privately if it is required?

    Thanks.

    #112362
    Pratik
    Participant

    Hi @webtrader,

    Add following code in your child theme’s functions.php file.

    
    /**
     * Modify parent slider option to randomize the slider
     */
    function helena_featured_slider() {
    	//helena_flush_transients();
    	global $wp_query;
    
    	$enable_slider = apply_filters( 'helena_get_option', 'featured_slider_option' );
    
    	// Get Page ID outside Loop
    	$page_id = $wp_query->get_queried_object_id();
    
    	// Front page displays in Reading Settings
    	$page_for_posts = get_option( 'page_for_posts' );
    
    	if ( 'entire-site' == $enable_slider  || ( ( is_front_page() || ( is_home() && $page_for_posts != $page_id ) ) && 'homepage' == $enable_slider  ) ) {
    		if ( ( !$output = get_transient( 'helena_featured_slider' ) ) ) {
    			echo '<!-- refreshing cache -->';
    
    			$output = '
    				<section id="feature-slider">
    					<div class="wrapper">
    						<div class="cycle-slideshow"
    						    data-cycle-log="false"
    						    data-cycle-pause-on-hover="true"
    						    data-cycle-swipe="true"
    						    data-cycle-random="true"
    						    data-cycle-fx="' . esc_attr( apply_filters( 'helena_get_option', 'featured_slider_transition_effect' ) ) . '"
    							data-cycle-speed="' . esc_attr( apply_filters( 'helena_get_option', 'featured_slider_transition_length' ) ) * 1000 . '"
    							data-cycle-timeout="' . esc_attr( apply_filters( 'helena_get_option', 'featured_slider_transition_delay' ) ) * 1000 . '"
    							data-cycle-loader="' . esc_attr( apply_filters( 'helena_get_option', 'featured_slider_image_loader' ) ) . '"
    							data-cycle-slides="> article"
    							>
    
    						    <!-- prev/next links -->
    						    <div class="cycle-prev"></div>
    						    <div class="cycle-next"></div>
    
    						    <!-- empty element for pager links -->
    	    					<div class="cycle-pager"></div>';
    
    	    					$select_slider 	= apply_filters( 'helena_get_option', 'featured_slider_type' );
    
    							// Select Slider
    							if ( 'demo-featured-slider' == $select_slider ) {
    								$output .= helena_demo_slider();
    							}
    							else if ( 'featured-post-slider' == $select_slider || 'featured-page-slider' == $select_slider || 'featured-category-slider' == $select_slider ) {
    								$output .= helena_post_page_category_slider();
    							}
    							elseif ( 'featured-image-slider' == $select_slider  ) {
    								$output .= helena_image_slider();
    							}
    
    			$output .= '
    						</div><!-- .cycle-slideshow -->
    					</div><!-- .wrapper -->
    				</section><!-- #feature-slider -->';
    
    			set_transient( 'helena_featured_slider', $output, 86940 );
    		}
    		echo $output;
    	}
    }
    

    If this does not work, then I will need your site url. Let me know and I will email you to get the details for site url.

    Regards,
    Pratik

    #112420
    webtrader
    Participant

    Hi @Pratik ,

    I appreciate the code. However it does not work for us. Would you please let me know how I can provide you with the URL privately?

    Thank you.

    #112459
    Pratik
    Participant

    Hi @webtrader,

    Please check your email. I have sent you details there.

    Regards,
    Pratik

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Randomize slides shown by Featured Slider’ is closed to new replies.