Hello!
Perhaps someone will be able to help me.
I built a website based on WordPress Sage and Tailwind CSS.
There is a carousel module in the project, which looks like that:
Carousel
The problem is that the last photo in the carousel block takes up two rows. I am not able to dynamically generate such content in the carousel, which would simultaneously change (scrolling right/left) and adjust responsively to the width of the screen (another attachment).
Have any of you encountered a similar challenge on Sage?
I found a component that perfectly reflects the effect I want to achieve: https://splidejs.com/extensions/grid
The problem is that the documentation is basically zero and I am unable to recreate the example in the link.
If anyone has an idea how to solve this, I would be grateful for a hint or direction. 🙂
2
Answers
Install Splide.js:
Start by installing the Splide.js library into your project. You can use npm or yarn for this:
npm install @splidejs/splide
After installation, make sure to include the Splide.js CSS and JavaScript files in your project.
Create HTML Structure:
In your WordPress template file, create an HTML structure that resembles the grid carousel structure. This can be a simple unordered list () with list items (
Initialize Splide.js:
In your JavaScript file, initialize Splide.js on the element with the .splide class:
Adjust the perPage option and breakpoints according to your design’s requirements.
Style Your Carousel:
Use your CSS to style the carousel as you need, adjusting the slide widths, paddings, margins, and other styles to create the grid effect.
if you want to use splide with the splide grid extension, you can try something like this:
Install the splide and splide grid extension via npm:
npm install @splidejs/splide
npm install @splidejs/splide-extension-grid
Create your HTML markup for the slides:
Import splide and splide grid extension, configure your splide instance and mount it, like this:
Note, you need to use
.mount({ Grid })
. There are other ways to do this too. Additionally, you could consider Swiper JS, which can also be used for grid-sliders.