Here is a useful snippet for those who need to display their slides in a random order.
The random display is handled in javascript but I might come with an even simplier solution with a WordPress hook in a future release of the theme.
add_action ('wp_footer','tc_randomize_slides' ); function tc_randomize_slides() { global $wp_query; $queried_id = get_queried_object_id(); $queried_id = ( !tc__f('__is_home') && $wp_query -> is_posts_page && !empty($queried_id) ) ? $queried_id : get_the_ID(); $slider_active = esc_attr(get_post_meta( $queried_id, $key = 'post_slider_check_key' , $single = true )); if ( tc__f('__is_home') && tc__f('__get_option','tc_front_slider') !=null) { $slider_active = true; } if(!$slider_active) { return; } ?> <script type='text/javascript'> jQuery(document).ready(function() { !function ( $) { //prevents js conflicts "use strict"; $.CustomizrSlidesShuffle = function() { var o = []; //get original slides nodes and order $('.czr-item' , '.carousel-inner').each(function() { $(this).removeClass('active'); o.push($(this)); }); //randomizes for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); //displays reordered slides o[0].addClass('active'); for (var i = 0; i < o.length - 1; i++) { o[i].after(o[i+1]); }; }; }(window.jQuery); //calls the function jQuery.CustomizrSlidesShuffle(); }); </script> <?php }
Where to paste this code? => in your functions.php file. I strongly recommend to create a child theme. Download a start-up child theme here.
Everything you need to know about child theme with Customizr here.
17 thoughts on “Customizr Slider : Randomize your slides”
how can you stop autoplay function of the slider?
I just wanna show one random image of the slider per page.
thx for this wonderful theme!
Is there ever going to be another way to do this without having to edit the functions.php file after every update?
Hello, the wordpress upgrade process implies the deleting of the the theme’s functions.php that’s why we strongly recommend (as written in the blue box below the snippet code) to build a child-theme. Using a child-theme and placing your functions in its functions.php will allow you to keep them when upgrading.
Hope this helps.
Hi there, would it be possible to make slider show random post?
Hi, I’ve looked around your site but can’t see if there is an update to making the slides random? Or is that a Pro feature? Thank you. 🙂
Oh dear oh dear, I just pasted the randomise slider code in my functions.php and my whole site crashed. : (
Tried to restore from backup but that’s not working either. Oh what have I done…
Hello AL,
Sorry for the inconvenience this has caused to you. I have accessed the website: http://algibsonauthor.com/ and found that the issue which you are experiencing is related to the theme ‘customizr’. Therefore, please reinstall the theme ‘customizr’ or contact the theme ‘customizr’ vendor or the support team of the theme ‘customizr’ to fix this issue.
Currently. I have set the default theme ‘twentytwelve’. Now, the website: http://algibsonauthor.com/ is working fine without any issues. If the issue persists, please let us know.
If you have any further questions, please update the Support Console.
Sincerely,
Shreyank N
Technical Specialist
Hi Al, this seems to be fixed now?
Best
Hi Al, you might want to take a quick look at this guide on how to handles problems with your WordPress themes.
Hope this helps and that your site will be back up soon!
Hi Nicholas, did you say you were adding in a setting for random slide sequence in Customizr?
Bonjour Nicolas,
Est-il possible de changer le mode d’apparition des images? Est-il possible de les faire apparaître simplement par transparence les unes après les autres sans avoir cet effet arrivées par la droite? Je suppose qu’il faut réécrire un script?
Bravo pour votre travail sur Customizr. Je le comprends petit à petit.
Bien à vous!
Hi Loïc, you might be interested by the snippet on how to change Customizr slider to fade effect.
Hope this helps aand thanks for your comment.
Indeed Nicolas, it’s helping beautifully. Just nice and soft, Thank you and Mister Bardell. All that is working perfectly.
Well done again. I will certainly have more questions, ‘petit à petit’…
All my best wishes
Great. Glad to read this!
Would love to have an easier solution to making the images random, looking forward to an update, thank you. 🙂
Hi Matt,
This is added in the ‘improvements’ list!
Thanks
Olá, quria saber como modificar as fotos do slider sendo que no thema que eu instalei não veio esta opção
http://siteideal.com.br/