Wordpress PHP Slider不删除图像,因为我从帖子中删除图像

时间:2018-06-10 19:34:19

标签: php wordpress image slider wordpress-theming

现在,我正在运行一些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)">&#10094; </button>
<button class="w3-button w3-display-right"onclick="plusDivs(+1)">&#10095; </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 WordPress post

The slider element that should be there.

The one that shoulds be

因此,当我从帖子中删除图像时,它不会从滑块元素中移除。

0 个答案:

没有答案