我正在抓取上传到该帖子的图像,并使用此功能:wp_get_attachment_image_src
<?php
$images = get_children( array( \'post_parent\' => $post->ID, \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'orderby\' => \'menu_order\', \'order\' => \'ASC\', \'numberposts\' => 2 ) );
if ( $images ) :
$total_images = count( $images );
$image = array_shift( $images );
$image_img_tag = wp_get_attachment_image_src( $image->ID, \'full\' );
?>
<div class="two_images">
<img src="<?php echo $image_img_tag[0] ?>">
</div>
如何获取上传到帖子的前两幅图像?我想我需要一份foreach声明的帮助。。并将其限制为两个。我试过了,但它只是一遍又一遍地打印出相同的第一张图像。。<?php foreach ($image as $images) {
echo "<img src=\'$image_img_tag[0]\'>";
} ?>
如果我回音$total_images
然后我得到2的正确计数