我的工作代码输出我的wordpress帖子中的所有图像,并将最后一张图像作为#last-img的背景,这是最后显示的图像。
我试图在我的代码中放置一个按钮,该按钮出现在#last-img中。我无法将其置于代码之外,因为当我尝试使用绝对定位时,它会将所有图像用作参考点
我的代码
<?php
preg_match_all('/(<img [^>]*>)/', get_the_content(), $images);
preg_match_all('/src="([^"]*)"/i', get_the_content(), $images1);
$count = count($images[1]);
$count1 = count($images1[1]);
foreach($images[1] as $k=> $img){
if($k == $count-1){
$format = '<div id="last-img" style="background:url(%s)"> ... </div>'; // Or $format = "<div id='last-img' style='background:url(%s)'> ... </div>";
$image = $images1[1][$count1-1];
echo sprintf($format,$image);
}else{
echo $img;
}
}
?>
链接代码
<div id="top-btn">
<div id="top-rotate"></div>
<a href="..."></a>
</div>
CSS
#top-btn {
display: block;
position: absolute;
z-index: 200;
right: 0; left: 0; bottom: 0;
margin: 0 auto;
height: 60px; width: 60px;
}