【发布时间】:2014-11-16 10:13:27
【问题描述】:
我正在尝试通过循环抓取图库图片,它是帖子的信息。我得到的只是图像来源,而不是标题。这是我的代码
<?php
/* The loop */
while ( have_posts() ) :
the_post();
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
/* Loop through all the image and output them one by one */
foreach( $gallery['src'] AS $src ) {
?>
<img src="<?php echo $src; ?>" class="my-custom-class" alt="Gallery image" />
<?php
}
endif;
endwhile;
?>
使用此循环,我只能在帖子中获取画廊图像的来源。但我也想抓取图片说明。
【问题讨论】:
-
$gallery是否包含“src”以外的其他字段?你能展示$gallery的整个结构吗?
标签: php image gallery wordpress