如何获得第二篇文章';Wordpress中的附加图像

如何获得第二篇文章';Wordpress中的附加图像,wordpress,image,attachment,Wordpress,Image,Attachment,此函数无法显示第二个图像。我只想要第二张图片作为文章附件 我只想要附件src,比如:如果post img=1 echo img src=“img1src”,如果post img=2 echo img src=“img1src”src=“img2src”,如果img=3 echo img1src img2src img3src 函数_图像() { 全球$员额; $attachments=获取子项(['post\u type'=>'attachments', “numberposts”=>-1, “

此函数无法显示第二个图像。我只想要第二张图片作为文章附件

我只想要附件src,比如:如果post img=1 echo img src=“img1src”,如果post img=2 echo img src=“img1src”src=“img2src”,如果img=3 echo img1src img2src img3src

函数_图像()
{
全球$员额;
$attachments=获取子项(['post\u type'=>'attachments',
“numberposts”=>-1,
“post_mime_type”=>“image”,
“post_状态”=>null,
'post_parent'=>$post->ID,
]);
若有($附件){
foreach($attachments作为$attachment){
$src=wp_get_attachment_image_src($attachment->ID,“attached image”);
$pics=计数($attachments);
如果($pics==2){
回声';
}
}
}
}

我需要第二张图片的地址。

我还没有测试它,但请尝试以下操作:

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

不,我很抱歉我的英语这么差。我只需要附件src,类似于:if post img=1 echo和if postImg=2 echo