【发布时间】:2018-01-14 07:56:51
【问题描述】:
对于 Wordpress 主题,我想创建一个函数(包含在 content.php 中),它获取附加到帖子的所有图像,为每个图像创建一个 <img>-string,最后创建并回显一个 @ 987654322@ 包含所有这些<img>-strings。
到目前为止,我能够获取所有图像并创建<img>-strings,但我很难将它们放入新的<div>。到目前为止,我的功能代码如下所示:
function create_imageslideshow() {
// Get the post ID
$iPostID = $post->ID;
// Get images for this post
$arrImages = get_attached_media( 'image' . $iPostID );
// If images exist for this post
if($arrImages) {
// Get array keys representing attached image numbers
$arrKeys = array_keys($arrImages);
foreach ($arrKeys as $iNum) {
// Get the full sized image url for the attachment
$sImageUrl = wp_get_attachment_url($iNum);
// Build the <img> string (parse regular <img>-tag)
$sImgString =
'<img id="' . $iNum . '"" src="' . $sImageUrl . '" alt="Thumbnail Image" title="Thumbnail Image" />';
// Print the image
echo $sImgString;
}
// Build slideshow ???
}
}
这成功地为每个图像创建了一个<img>-tag 并对其进行回显,以便图像显示在网站上。但是,我需要在<div> 中回显它们,而不是仅仅回显图像。有没有办法将为每个图像创建的所有字符串放入一个数组中,然后我可以将其放入 <div> 的新字符串中?
【问题讨论】:
-
每个带有新 div 的图像标签还是一个 div 中的所有图像?
-
@Khushboo 一个 div 中的所有图像
标签: php html css arrays wordpress