wordpress,如何获得第二篇文章附加图像

时间:2012-12-03 04:45:18

标签: wordpress attachment

此功能无法显示第二张图片,我只想要第二张图片作为帖子附件。

我很抱歉我的英雄太糟糕了。我只想要附件src,例如:if post img = 1 echo img src =“img1src”如果post img = 2 echo img src =“img1src”src =“img2src”,如果img = 3 echo img1src img2src img3src ..

function the_images() {
global $post;
$attachments = get_children( array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_mime_type' => 'image', 'post_status' => null, 'post_parent' => $post->ID ) ); 
if ($attachments) {
  foreach ( $attachments as $attachment ) {
  $src = wp_get_attachment_image_src( $attachment->ID, "attached-image");
  $pics = count($attachments);
  if ($pics == 2) {echo'<img src="'.$src[0].'"/><img src="'.$src[1].'"/>';}
  }
}
}

我需要第二张图片的地址

1 个答案:

答案 0 :(得分:0)

我没有测试过,但试试这个:

$pics = count($attachments, COUNT_RECURSIVE ); // For multidimensional array.