I have a client that wanted their website to be primarily just the home page. They also want mobile and tablet users to just be able to swipe through the pages. I found some potential solutions but they were mostly very large, overly complex plugins for a simple need. I’ve been wanting to dive into the WP API and I found this to be a great opportunity. This is VERY basic usage of the WP API, but hey, I’m just getting started. And please read to the bottom if you are knowledgeable of the WP API as I’m a bit confused on why something I tried did not work.
So here is my simple solution for the sliding pages (works for posts and other post_types as well).
JSSOR
First we need to include a slider library. I went with JSSOR because it works great with loads of features and is easy to get started quickly.
http://www.jssor.com/development/
I enqueue this in my themes functions.php file
function theme_scripts() {
wp_enqueue_script( 'jssor', get_template_directory_uri() . '/js/jssor.slider.mini.js', array() );
}
add_action( 'wp_enqueue_scripts', 'theme_scripts' );
build_sliders
Then we have our function for building the slider. This can be tweaked to your liking, I wanted to have title, featured image and content. We take in the slider id and height as parameters and we also take in the full url for the WP API request. We format around the loop through our results with the required JSSOR slider containers. The jQuery at the bottom is used to make the slider responsive.
/**
* Build sliders
*/
function build_sliders( $slider_id, $slider_height, $api_request ) {
?>
';
}
?>