I recently worked on a small plugin that would allow selecting a slider to be displayed at the top of a custom taxonomy archive template.
For the plugin to work properly, I needed to get a list of sliders. I knew about the putRevSlider() function that could be used in a plugin or theme to output a slider, but after looking around, I couldn’t find something for getting a list of sliders.
After a while of digging, I found the following article: https://www.themepunch.com/faq/show-a-random-slider-on-any-given-page/
That article suggests using the following to get a list of slider aliases:
// get a list of all available sliders
$my_sliders = new RevSlider();
// grab the "alias" names of the sliders
$my_slider_array = $my_sliders->getAllSliderAliases();
Because this code requires that the `RevSlider` class exist, I would suggest using something like the following:
if ( class_exists( 'RevSlider' ) ) {
$rev_slider = new RevSlider();
$sliders = $rev_slider->getAllSliderAliases();
} else {
$sliders = array();
}
Checking that the class exists will prevent you from running into errors in your plugin or theme if Revolution Slider is deactivated or deleted for some reason.
Leave a Reply