现在,我正在运行一些PHP代码,将Wordpress帖子中的图像转换为滑块元素。
<?php
$ticker = 0;
$attachments= get_attached_media( 'image', $post->ID );
foreach($attachments as $att_id => $attachment) {
$full_img_url[$ticker] = wp_get_attachment_url($attachment->ID);
?>
<img class="mySlides" src="<?php echo $full_img_url[$ticker]; ?>" >
<?php
$ticker ++;
}
?>
<button class="w3-button w3-display-left" onclick="plusDivs(-1)">❮ </button>
<button class="w3-button w3-display-right"onclick="plusDivs(+1)">❯ </button>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length} ;
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
我从帖子中删除图片时出现问题。
The slider element that should be there.
因此,当我从帖子中删除图像时,它不会从滑块元素中移除。