On php, you can do this:
Create the file incswiper.php (from the words "include swiper", but it is possible with a different name). In this file we will have the "building blocks" to build different versions of Swiper.
<?php function GetSwiper($pagename) // вариант с Pagination { echo '<div class="swiper-container">'; GetSwiperContent1($pagename); GetSwiperPagination1($pagename); GetSwiperInit1($pagename); echo '</div>'; } function GetSwiper2($pagename) // вариант без Pagination, например (можно компоновать разные варианты, составные части тоже можно добавить любые, пользуясь Swiper API). { echo '<div class="swiper-container">'; GetSwiperContent2($pagename); // функцию с контентом для Swiper2 по аналогии с первой не составит труда составить, как и функцию инициализации и др. GetSwiperInit2($pagename); echo '</div>'; } function GetSwiperContent1($pagename) { echo '<div class="swiper-wrapper"> <div class="swiper-slide"> <a href="#"> <img src="images/img1.jpg" alt="ALT1"> </a> </div> <div class="swiper-slide"> <a href="#"> <img src="images/img2.jpg" alt="ALT2"> </a> </div> <div class="swiper-slide"> <a href="#"> <img src="images/img3.jpg" alt="ALT3"> </a> </div> <div class="swiper-slide"> <a href="#"> <img src="images/img4" alt="ALT4"> </a> </div> </div>'; } function GetSwiperPagination1($pagename) { echo '<div class="swiper-pagination"></div>'; } function GetSwiperInit1($pagename) { echo '<script src="js/swiper.min.js"></script> <script> var Swiper = new Swiper(\'.swiper-container\', { loop: true, speed: 1200, pagination: \'.swiper-pagination\', paginationClickable: true, effect: \'fade\', // Could be "slide", "fade", "cube", "coverflow" or "flip" autoplay: 6000, autoplayDisableOnInteraction: false }); </script>'; }
And then in the file where we will connect Swiper, we write the line `include 'inc / incswiper.php';
And then in the right place we "spit out" the necessary variant of Swiper (Swiper1, 2, 3 ... n - you can assemble these variants as a constructor from bricks). In general, there are a few "nuances" here (for example, a file handler and in the right place to enter the variable pagename), but I didn’t want to post the whole project, but suggest a method. I hope the idea is clear!
The GetSwiper1 and GetSwiper2 functions are versions of the Swiper assembly, but all other functions are the “building blocks” for them. Swiper options can be collected as many as you want, and you can use your own “building blocks” for each one, but nobody forbids to reuse the same ones, in this case you need to invent a meaningful namespace, otherwise there will be confusion.