我直接从codex. 
function echo_first_image ($postID)
{                   
    $args = array(
    \'numberposts\' => 1,
    \'order\'=> \'ASC\',
    \'post_mime_type\' => \'image\',
    \'post_parent\' => $postID,
    \'post_status\' => null,
    \'post_type\' => \'attachment\'
    );
    $attachments = get_children( $args );
    //print_r($attachments);
    if ($attachments) {
        foreach($attachments as $attachment) {
            $image_attributes = wp_get_attachment_image_src( $attachment->ID, \'thumbnail\' )  ? wp_get_attachment_image_src( $attachment->ID, \'thumbnail\' ) : wp_get_attachment_image_src( $attachment->ID, \'full\' );
            echo \'<img src="\'.wp_get_attachment_thumb_url( $attachment->ID ).\'" class="current">\';
        }
    }
}
 我这样叫它在循环中
echo_first_image ($post->ID);函数确实调用了,但没有得到任何输出。。。据我所知$attachments
我在使用的帖子中确实有一张图片。这不是一张特色图片,也不是在画廊里,只是在帖子里。
我是做错了什么,还是代码有什么问题?
 
                    最合适的回答,由SO网友:Diana 整理而成
                    如果你愿意display an image that is inserted into your content (例如,热链接图像),必须使用如下函数(source):
外接程序functions.php:
function catch_that_image() {
  global $post, $posts;
  $first_img = \'\';
  ob_start();
  ob_end_clean();
  $output = preg_match_all(\'/<img.+src=[\\\'"]([^\\\'"]+)[\\\'"].*>/i\', $post->post_content, $matches);
  $first_img = $matches [1] [0];
  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}
 然后放置
<?php echo catch_that_image() ?> 显示图像的位置。
注意:刚放在内容中的热链接图像不能设置为特色图像,即bultin WordPress\'feature。