Ensure slideshow assets render reliably with shortcodes
This commit is contained in:
1 parent
12e1c7b01e
commit
38c935b425
1 file changed
+25
-9
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
Plugin Name: Super Simple Slideshow
|
||||
Description: A simple image slideshow managed from the WordPress admin area.
|
||||
Version: 1.1.0
|
||||
Version: 1.1.1
|
||||
Author: ai-bot
|
||||
*/
|
||||
|
||||
@@ -167,21 +167,37 @@ add_shortcode('super_simple_slideshow', function () {
|
||||
return '';
|
||||
}
|
||||
|
||||
wp_register_style('super-simple-slideshow', false, array(), '1.1.0');
|
||||
wp_enqueue_style('super-simple-slideshow');
|
||||
wp_add_inline_style('super-simple-slideshow', '.super-simple-slideshow .super-simple-slide{display:none;width:100%;height:auto}.super-simple-slideshow .super-simple-slide.active{display:block}');
|
||||
|
||||
wp_register_script('super-simple-slideshow', false, array(), '1.1.0', true);
|
||||
wp_enqueue_script('super-simple-slideshow');
|
||||
wp_add_inline_script('super-simple-slideshow', '(function(){document.querySelectorAll(".super-simple-slideshow").forEach(function(slideshow){var slides=slideshow.querySelectorAll(".super-simple-slide");if(slides.length<2){return;}var current=0;window.setInterval(function(){slides[current].classList.remove("active");current=(current+1)%slides.length;slides[current].classList.add("active");},5000);});})();');
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<style>
|
||||
.super-simple-slideshow .super-simple-slide { display: none; width: 100%; height: auto; }
|
||||
.super-simple-slideshow .super-simple-slide.active { display: block; }
|
||||
</style>
|
||||
<div class="super-simple-slideshow">
|
||||
<?php foreach ($ids as $index => $id) : ?>
|
||||
<?php echo wp_get_attachment_image($id, 'full', false, array('class' => $index === 0 ? 'super-simple-slide active' : 'super-simple-slide')); ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<script>
|
||||
(function () {
|
||||
document.querySelectorAll('.super-simple-slideshow').forEach(function (slideshow) {
|
||||
if (slideshow.dataset.superSimpleInitialized) {
|
||||
return;
|
||||
}
|
||||
slideshow.dataset.superSimpleInitialized = 'true';
|
||||
var slides = slideshow.querySelectorAll('.super-simple-slide');
|
||||
if (slides.length < 2) {
|
||||
return;
|
||||
}
|
||||
var current = 0;
|
||||
window.setInterval(function () {
|
||||
slides[current].classList.remove('active');
|
||||
current = (current + 1) % slides.length;
|
||||
slides[current].classList.add('active');
|
||||
}, 5000);
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
});
|
||||
Reference in new issue
Block a user