Splide is one of the scripts that gets registered and ready to be used when the Scripts module is enabled in Oxy Toolbox.
This tutorial provides the steps to set up a responsive posts slider in Oxygen using Splide.
With a few changes we can also set up a full-width slider like this.
Let us register a custom image size for the slide images so they all look uniform.
Install and activate Code Snippets plugin.
Go to Snippets > Add New.
Title: Custom image sizes
Code:
add_image_size( 'slider_image', 480, 300, true );
Set the snippet to run everywhere. Save changes and activate.
If your posts already have featured images, you will need to regenerate thumbnails.
Edit the Page/Template (with Oxygen) where you would like to have the slider.
If you want to paste the entire structure from the demo site, install and activate Hydrogen Pack (premium) or Hydrogen Paste (free), reload Oxygen editor and paste the following:
eyJzb3VyY2UiOiJodHRwczovL3NwbGlkZS53cGRlbW8uZGV2IiwiY29tcG9uZW50Ijp7ImlkIjoyLCJuYW1lIjoiY3Rfc2VjdGlvbiIsIm9wdGlvbnMiOnsiY3RfaWQiOjIsImN0X3BhcmVudCI6MTAwMDE5LCJzZWxlY3RvciI6InNlY3Rpb24tMi03NiIsImFjdGl2ZXNlbGVjdG9yIjpmYWxzZSwiY2xhc3NlcyI6W119LCJjaGlsZHJlbiI6W3siaWQiOjY3LCJuYW1lIjoiY3RfZGl2X2Jsb2NrIiwib3B0aW9ucyI6eyJjdF9pZCI6NjcsImN0X3BhcmVudCI6Miwic2VsZWN0b3IiOiJkaXZfYmxvY2stNjctNzYiLCJvcmlnaW5hbCI6eyJ3aWR0aCI6IjEwMCIsIndpZHRoLXVuaXQiOiIlIn0sImNsYXNzZXMiOlsic3BsaWRlIl0sImFjdGl2ZXNlbGVjdG9yIjpmYWxzZX0sImNoaWxkcmVuIjpbeyJpZCI6NjYsIm5hbWUiOiJjdF9kaXZfYmxvY2siLCJvcHRpb25zIjp7ImN0X2lkIjo2NiwiY3RfcGFyZW50Ijo2Nywic2VsZWN0b3IiOiJkaXZfYmxvY2stNjYtNzYiLCJvcmlnaW5hbCI6eyJ3aWR0aCI6IjEwMCIsIndpZHRoLXVuaXQiOiIlIn0sImNsYXNzZXMiOlsic3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dHJpZ2h0OiAtMy41cmVtO1xuXHR9XG59XG5cbi5zcGxpZGVfX3BhZ2luYXRpb25fX3BhZ2UuaXMtYWN0aXZlIHtcblx0YmFja2dyb3VuZDogIzMzMztcblx0dHJhbnNmb3JtOiBzY2FsZSgxKTtcbn0ifSwiYWN0aXZlc2VsZWN0b3IiOmZhbHNlLCJjdF9jb250ZW50IjoiIn0sImRlcHRoIjoxfV0sImRlcHRoIjozfSwiY2xhc3NlcyI6eyJzcGxpZGUiOnsib3JpZ2luYWwiOnt9fSwic3BsaWRlX190cmFjayI6eyJvcmlnaW5hbCI6eyJwYWRkaW5nLWJvdHRvbSI6IjQwIn19LCJzcGxpZGVfX2xpc3QiOnsib3JpZ2luYWwiOnt9fSwic3BsaWRlX19zbGlkZSI6eyJvcmlnaW5hbCI6e319fSwiY29sb3JzIjp7fX0=
Add a Section.
Add a Div inside the Section. Set its width to 100%. Assign a class of splide
.
Add another Div inside the above Div. Set its width to 100%. Assign a class of splide__track
. Set a bottom padding of 40px for space between the images and pagination bullets.
Add a Repeater inside the above Div.
Set this manual query:
post_type=post&posts_per_page=5&no_found_rows=true
Select the Repeater’s Div and the elements you want to show for each slide. In this example, let’s add featured image and title both linking to the single post.
Add a Link Wrapper. Click data
in the URL field and select permalink.
Add an Image inside the Link Wrapper, click data
for Image URL and select Featured Image of Medium size.
Then change medium
in the populated Image URL to slider_image
.
Let’s add the post title below the image. + Add > WordPress > Dynamic Data > Title. Set your desired font size (say 20px) and heading tag (h3). Add a top margin of 10px.
Select the Section and add a Code Block.
PHP & HTML:
<?php
wp_enqueue_style( 'oxy_toolbox_scripts_splide' );
wp_enqueue_script( 'oxy_toolbox_scripts_splide' );
?>
CSS:
.splide__arrow {
margin-top: -45px;
}
@media only screen and (min-width: 1218px) {
.splide__arrow--prev {
left: -3.5rem;
}
.splide__arrow--next {
right: -3.5rem;
}
}
.splide__pagination__page.is-active {
background: #333;
transform: scale(1);
}
JS:
(function ($) {
$(document).ready(function(){
// do not run the code in Oxygen editor.
if(window.angular) return;
new Splide( '.splide', {
perPage: 3,
gap: '30px',
breakpoints: {
'767': {
perPage: 2,
arrows: false,
// pagination: false,
},
'479': {
perPage: 1,
arrows: true,
},
}
} ).mount();
});
})(jQuery);
and we are done.
Slider will not appear in the Oxygen editor but should be working on the front end.