我有一个函数可以从 Wordpress 的内容中回显图像的 URL。
我的功能现在没问题了
// Get Image Attachments
function sa_get_image($postid=0, $size='thumbnail') { //it can be thumbnail or full
    if ($postid<1)
    $postid = get_the_ID();
    $thumb = get_post_meta($postid, "thumb", TRUE); // Declare the custom field for the image
    if ($thumb != null or $thumb != '') {
        echo $thumb;
    }
    elseif ($images = get_children(array( //If you upload an image function gets first image
        'post_parent' => $postid,
        'post_type' => 'attachment',
        'numberposts' => '5',
        'post_mime_type' => 'image', )))
        foreach($images as $image) {
            $thumbnail=wp_get_attachment_image_src($image->ID, $size);
            ?>
    <?php echo $thumbnail[0]; ?>
    <?php }
        else { //If you don't upload or declare as thumb custom field func. gets custom (default) image
        echo get_bloginfo ( 'template_directory' ); //same as wp-content/themes/your-theme/
        echo '/images/image-pending.gif'; // Put this image into your themes images folder and set the path here
    }
}
现在唯一的问题是,         <?php echo $thumbnail[0]; ?>如果有多个图像,它会回显所有图像,如下所示
<img src="    http://applesiam.com/wp-content/uploads/2555-05-02_19h14_34-150x150.png        http://applesiam.com/wp-content/uploads/2555-05-02_19h14_11-150x150.png        http://applesiam.com/wp-content/uploads/2555-05-02_19h13_43-150x123.png        http://applesiam.com/wp-content/uploads/2555-05-02_19h13_20-150x150.png        http://applesiam.com/wp-content/uploads/2555-05-02_19h13_17-150x150.png    ">
正如你所看到的,它只是被一些空格隔开。
现在我只想拥有最后一张图像,如果有多个图像$thumbnail
我不是 PHP 方面的专家,因为我的 PHP 课程将于下周开始。
提前感谢您提出的任何建议。