【发布时间】:2016-03-13 18:41:42
【问题描述】:
我有以下代码,它以我的 Wordpress 帖子中的最后一张图片为目标,并将#first-img 放在上面,它只留下其他图片。
<div id="s-img" class="row">
<?php
preg_match_all('/(<img [^>]*>)/', get_the_content(), $images);
for( $i=0; isset($images[1]) && $i < count($images[1]); $i++ ) {
if ($i == end(array_keys($images[1]))) {
echo sprintf('<div id="last-img">%s</div>', $images[1][$i]);
continue;
}
echo $images[1][$i];
}
?>
</div>
css
#last-image {
position: absolute
height: 50px; width: 50px;
background-color: red;
}
问题是我希望它把#first-img 放在图像的顶部,而不是图像本身。现在它替换了图像。
渲染的 html - 在图像和最后一张图像上
<div id="s-img" class="row">
<img class="alignnone size-large wp-image-396" src="http://localhost/wordpress/wp-content/uploads/2015/12/img3-1008x720.jpg" alt="img3" height="720" width="1008"> </img>
</div>
<div id="last-img">
<img class="alignnone size-large wp-image-397" src="http://localhost/wordpress/wp-content/uploads/2015/12/img4-1080x720.jpg" alt="img4" height="720" width="1080"></img>
</div>
【问题讨论】:
-
请从浏览器发布呈现的 HTML,因为 PHP 代码将没有用处
-
请复制并粘贴屏幕截图无助于调试问题,谢谢
-
添加到
.rowdiv -position:relative
标签: php jquery html css wordpress